]> granicus.if.org Git - nethack/commitdiff
Fix text replacement warning
authorDean Luick <dean@nethack.org>
Sun, 17 Jan 2021 20:12:58 +0000 (14:12 -0600)
committerDean Luick <dean@nethack.org>
Thu, 21 Jan 2021 04:37:37 +0000 (22:37 -0600)
Using strncpy to cut off copying a terminating NUL yields a gcc
warning.  Just use memcpy instead.

src/insight.c
src/pager.c
src/pline.c
src/write.c

index a5cb1ecb62324e20ed592ce67b0e5a2ba63e476f..4d69b643011604acf62bcb62253d0ab1c6930e16 100644 (file)
@@ -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)
index 20346430ea261b336a6955b1f13215b51e5a4652..47d18be2aa36c790a46b1a6d35c8cc9f1901a6e8 100644 (file)
@@ -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) {
index f88a34d887cedfb23c39090d6adf4bdf6caa84be..957e59f0a5f9868bf256dbb0138b93d78e9b7f65 100644 (file)
@@ -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];
index fb0d28a6ad1b5c35504e15dcad43aadf2eaeb252..8029ab33bd7390d6bd3f6819e51d0aabac78d2c3 100644 (file)
@@ -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 */
     }