From 9e6bddac10f046fd72580c66ae3460e075237b32 Mon Sep 17 00:00:00 2001 From: nhmall Date: Sat, 12 Mar 2022 21:49:32 -0500 Subject: [PATCH] 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); | ^~~~~~~ --- src/artifact.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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); }