]> granicus.if.org Git - nethack/commitdiff
warning fix artifact.c
authornhmall <nhmall@nethack.org>
Sun, 13 Mar 2022 02:49:32 +0000 (21:49 -0500)
committernhmall <nhmall@nethack.org>
Sun, 13 Mar 2022 02:49:32 +0000 (21:49 -0500)
artifact.c: In function 'dump_artifact_info':
artifact.c:1088:37: warning: '%s' directive writing up to 255 bytes into a region of size 218 [-Wformat-overflow=]
 1088 |             Sprintf(buf, "  %-36.36s%s", artiname(m), buf2);
      |                                     ^~                ~~~~
In file included from ../include/config.h:652,
                 from ../include/hack.h:10,
                 from artifact.c:6:
../include/global.h:255:24: note: 'sprintf' output between 39 and 294 bytes into a destination of size 256
  255 | #define Sprintf (void) sprintf
artifact.c:1088:13: note: in expansion of macro 'Sprintf'
 1088 |             Sprintf(buf, "  %-36.36s%s", artiname(m), buf2);
      |             ^~~~~~~

src/artifact.c

index aef17162e814071775455c0b597ce9aa5b683f66..18d981b21c4af1b0ea3f7a60a0dda364426a6ad8 100644 (file)
@@ -1067,7 +1067,8 @@ dump_artifact_info(winid tmpwin)
 
     putstr(tmpwin, iflags.menu_headings, "Artifacts");
     for (m = 1; m <= NROFARTIFACTS; ++m) {
-        Sprintf(buf2, "[%s%s%s%s%s%s%s%s%s]", /* 9 bits overall */
+        Snprintf(buf2, sizeof buf2,
+                "[%s%s%s%s%s%s%s%s%s]", /* 9 bits overall */
                 artiexist[m].exists ? "exists;" : "",
                 artiexist[m].found  ? " hero knows;" : "",
                 /* .exists and .found have different punctuation because
@@ -1085,7 +1086,7 @@ dump_artifact_info(winid tmpwin)
         else
 #else
             /* "The Platinum Yendorian Express Card" is 35 characters */
-            Sprintf(buf, "  %-36.36s%s", artiname(m), buf2);
+            Snprintf(buf, sizeof buf, "  %-36.36s%s", artiname(m), buf2);
 #endif
         putstr(tmpwin, 0, buf);
     }