Fix text replacement warning

Using strncpy to cut off copying a terminating NUL yields a gcc
warning.  Just use memcpy instead.
This commit is contained in:
Dean Luick
2021-01-17 14:12:58 -06:00
parent 5dc5ece412
commit f63d435c6d
4 changed files with 5 additions and 5 deletions

View File

@@ -1382,8 +1382,8 @@ int final;
else if ((HClairvoyant || EClairvoyant) && BClairvoyant) { else if ((HClairvoyant || EClairvoyant) && BClairvoyant) {
Strcpy(buf, from_what(-CLAIRVOYANT)); Strcpy(buf, from_what(-CLAIRVOYANT));
if (!strncmp(buf, " because of ", 12)) if (!strncmp(buf, " because of ", 12))
/* overwrite substring; strncpy doesn't add terminator */ /* overwrite substring */
(void) strncpy(buf, " if not for ", 12); memcpy(buf, " if not for ", 12);
enl_msg(You_, "could be", "could have been", " clairvoyant", buf); enl_msg(You_, "could be", "could have been", " clairvoyant", buf);
} }
if (Infravision) if (Infravision)

View File

@@ -692,7 +692,7 @@ char *supplemental_name;
(note: strncpy() only terminates output string if the specified (note: strncpy() only terminates output string if the specified
count is bigger than the length of the substring being copied) */ count is bigger than the length of the substring being copied) */
if (!strncmp(dbase_str, "moist towel", 11)) if (!strncmp(dbase_str, "moist towel", 11))
(void) strncpy(dbase_str += 2, "wet", 3); /* skip "mo" replace "ist" */ memcpy(dbase_str += 2, "wet", 3); /* skip "mo" replace "ist" */
/* Make sure the name is non-empty. */ /* Make sure the name is non-empty. */
if (*dbase_str) { if (*dbase_str) {

View File

@@ -157,7 +157,7 @@ VA_DECL(const char *, line)
/* truncate, preserving the final 3 characters: /* truncate, preserving the final 3 characters:
"___ extremely long text" -> "___ extremely l...ext" "___ extremely long text" -> "___ extremely l...ext"
(this may be suboptimal if overflow is less than 3) */ (this may be suboptimal if overflow is less than 3) */
(void) strncpy(pbuf + BUFSZ - 1 - 6, "...", 3); memcpy(pbuf + BUFSZ - 1 - 6, "...", 3);
/* avoid strncpy; buffers could overlap if excess is small */ /* avoid strncpy; buffers could overlap if excess is small */
pbuf[BUFSZ - 1 - 3] = line[ln - 3]; pbuf[BUFSZ - 1 - 3] = line[ln - 3];
pbuf[BUFSZ - 1 - 2] = line[ln - 2]; pbuf[BUFSZ - 1 - 2] = line[ln - 2];

View File

@@ -171,7 +171,7 @@ register struct obj *pen;
nm += 3; nm += 3;
if ((bp = strstri(nm, " armour")) != 0) { if ((bp = strstri(nm, " armour")) != 0) {
(void) strncpy(bp, " armor ", 7); /* won't add '\0' */ memcpy(bp, " armor ", 7);
(void) mungspaces(bp + 1); /* remove the extra space */ (void) mungspaces(bp + 1); /* remove the extra space */
} }