From: Dean Luick Date: Sun, 17 Jan 2021 20:12:58 +0000 (-0600) Subject: Fix text replacement warning X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f63d435c6db3ea03f02418f6ccd94f8ce84acad5;p=nethack Fix text replacement warning Using strncpy to cut off copying a terminating NUL yields a gcc warning. Just use memcpy instead. --- diff --git a/src/insight.c b/src/insight.c index a5cb1ecb6..4d69b6430 100644 --- a/src/insight.c +++ b/src/insight.c @@ -1382,8 +1382,8 @@ int final; else if ((HClairvoyant || EClairvoyant) && BClairvoyant) { Strcpy(buf, from_what(-CLAIRVOYANT)); if (!strncmp(buf, " because of ", 12)) - /* overwrite substring; strncpy doesn't add terminator */ - (void) strncpy(buf, " if not for ", 12); + /* overwrite substring */ + memcpy(buf, " if not for ", 12); enl_msg(You_, "could be", "could have been", " clairvoyant", buf); } if (Infravision) diff --git a/src/pager.c b/src/pager.c index 20346430e..47d18be2a 100644 --- a/src/pager.c +++ b/src/pager.c @@ -692,7 +692,7 @@ char *supplemental_name; (note: strncpy() only terminates output string if the specified count is bigger than the length of the substring being copied) */ 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. */ if (*dbase_str) { diff --git a/src/pline.c b/src/pline.c index f88a34d88..957e59f0a 100644 --- a/src/pline.c +++ b/src/pline.c @@ -157,7 +157,7 @@ VA_DECL(const char *, line) /* truncate, preserving the final 3 characters: "___ extremely long text" -> "___ extremely l...ext" (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 */ pbuf[BUFSZ - 1 - 3] = line[ln - 3]; pbuf[BUFSZ - 1 - 2] = line[ln - 2]; diff --git a/src/write.c b/src/write.c index fb0d28a6a..8029ab33b 100644 --- a/src/write.c +++ b/src/write.c @@ -171,7 +171,7 @@ register struct obj *pen; nm += 3; 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 */ }