From: nhmall Date: Sun, 13 Mar 2022 02:49:32 +0000 (-0500) Subject: warning fix artifact.c X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9e6bddac10f046fd72580c66ae3460e075237b32;p=nethack warning fix artifact.c 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); | ^~~~~~~ --- diff --git a/src/artifact.c b/src/artifact.c index aef17162e..18d981b21 100644 --- a/src/artifact.c +++ b/src/artifact.c @@ -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); }