]> granicus.if.org Git - nethack/commitdiff
clear some more format-overflow warnings
authornhmall <nhmall@nethack.org>
Mon, 1 Feb 2021 21:36:17 +0000 (16:36 -0500)
committernhmall <nhmall@nethack.org>
Mon, 1 Feb 2021 21:36:17 +0000 (16:36 -0500)
clear some -Wformat-overflow warnings being experienced with
i586-pc-msdosdjgpp-gcc (GCC) 10.2.0 cross-compiler

--
Warnings log:

botl.c: In function 'status_hilite_menu_add':
botl.c:3661:38: warning: ' or ' directive writing 4 bytes into a region of size between 1 and 80 [-Wformat-overflow=]
 3661 |                     Sprintf(obuf, "%s or %s",
      |                                      ^~~~
In file included from ../include/config.h:631,
                 from ../include/hack.h:10,
                 from botl.c:6:
../include/global.h:274:24: note: 'sprintf' output between 5 and 163 bytes into a destination of size 80
  274 | #define Sprintf (void) sprintf
botl.c:3661:21: note: in expansion of macro 'Sprintf'
 3661 |                     Sprintf(obuf, "%s or %s",
      |                     ^~~~~~~

do_name.c: In function 'getpos_menu':
do_name.c:594:37: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=]
  594 |             Sprintf(fullbuf, "%s%s%s", firstmatch,
      |                                     ^
In file included from ../include/config.h:631,
                 from ../include/hack.h:10,
                 from do_name.c:6:
../include/global.h:274:24: note: 'sprintf' output 1 or more bytes (assuming 257) into a destination of size 256
  274 | #define Sprintf (void) sprintf
do_name.c:594:13: note: in expansion of macro 'Sprintf'
  594 |             Sprintf(fullbuf, "%s%s%s", firstmatch,
      |             ^~~~~~~

dungeon.c: In function 'print_dungeon':
dungeon.c:2172:27: warning: '%s' directive writing up to 1407 bytes into a region of size 256 [-Wformat-overflow=]
 2172 |             Sprintf(buf, "%s: %s %d", dptr->dname, descr, dptr->depth_start);
      |                           ^~
In file included from ../include/config.h:631,
                 from ../include/hack.h:10,
                 from dungeon.c:6:
../include/global.h:274:24: note: 'sprintf' output between 10 and 1427 bytes into a destination of size 256
  274 | #define Sprintf (void) sprintf
dungeon.c:2172:13: note: in expansion of macro 'Sprintf'
 2172 |             Sprintf(buf, "%s: %s %d", dptr->dname, descr, dptr->depth_start);
      |             ^~~~~~~
dungeon.c:2169:27: warning: '%s' directive writing up to 1407 bytes into a region of size 256 [-Wformat-overflow=]
 2169 |             Sprintf(buf, "%s: %s %d to %d", dptr->dname, makeplural(descr),
      |                           ^~
dungeon.c:2169:26: note: directive argument in the range [-21474836472147483646]
 2169 |             Sprintf(buf, "%s: %s %d to %d", dptr->dname, makeplural(descr),
      |                          ^~~~~~~~~~~~~~~~~
In file included from ../include/config.h:631,
                 from ../include/hack.h:10,
                 from dungeon.c:6:
../include/global.h:274:24: note: 'sprintf' output 10 or more bytes (assuming 1427) into a destination of size 256
  274 | #define Sprintf (void) sprintf
dungeon.c:2169:13: note: in expansion of macro 'Sprintf'
 2169 |             Sprintf(buf, "%s: %s %d to %d", dptr->dname, makeplural(descr),
      |             ^~~~~~~
dungeon.c: In function 'print_mapseen':
dungeon.c:3185:33: warning: '%s' directive writing up to 255 bytes into a region of size 249 [-Wformat-overflow=]
 3185 |         Sprintf(outbuf, " (play %s to open or close drawbridge)", tmp);
      |                                 ^~                                ~~~
In file included from ../include/config.h:631,
                 from ../include/hack.h:10,
                 from dungeon.c:6:
../include/global.h:274:24: note: 'sprintf' output between 37 and 292 bytes into a destination of size 256
  274 | #define Sprintf (void) sprintf
dungeon.c:3185:9: note: in expansion of macro 'Sprintf'
 3185 |         Sprintf(outbuf, " (play %s to open or close drawbridge)", tmp);
      |         ^~~~~~~
dungeon.c:3350:35: warning: '%s' directive writing up to 255 bytes into a region of size 240 [-Wformat-overflow=]
 3350 |         Sprintf(buf, "%sThe castle%s.", PREFIX, tunesuffix(mptr, tmpbuf));
      |                                   ^~
In file included from ../include/config.h:631,
                 from ../include/hack.h:10,
                 from dungeon.c:6:
../include/global.h:274:24: note: 'sprintf' output between 18 and 273 bytes into a destination of size 256
  274 | #define Sprintf (void) sprintf
dungeon.c:3350:9: note: in expansion of macro 'Sprintf'
 3350 |         Sprintf(buf, "%sThe castle%s.", PREFIX, tunesuffix(mptr, tmpbuf));
      |         ^~~~~~~

explode.c:541:69: warning: '%s' directive writing up to 255 bytes into a region of size 236 [-Wformat-overflow=]
  541 |                     Sprintf(g.killer.name, "caught %sself in %s own %s", uhim(),
      |                                                                     ^~
In file included from ../include/config.h:631,
                 from ../include/hack.h:10,
                 from explode.c:5:
../include/global.h:274:24: note: 'sprintf' output 21 or more bytes (assuming 276) into a destination of size 256
  274 | #define Sprintf (void) sprintf
explode.c:541:21: note: in expansion of macro 'Sprintf'
  541 |                     Sprintf(g.killer.name, "caught %sself in %s own %s", uhim(),
      |                     ^~~~~~~

hacklib.c: In function 'yyyymmddhhmmss':
hacklib.c:1034:28: warning: '%02d' directive writing between 2 and 11 bytes into a region of size between 4 and 11 [-Wformat-overflow=]
 1034 |     Sprintf(datestr, "%04ld%02d%02d%02d%02d%02d", datenum, lt->tm_mon + 1,
      |                            ^~~~
hacklib.c:1034:22: note: directive argument in the range [-21474836472147483647]
 1034 |     Sprintf(datestr, "%04ld%02d%02d%02d%02d%02d", datenum, lt->tm_mon + 1,
      |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../include/config.h:631,
                 from ../include/hack.h:10,
                 from hacklib.c:7:
../include/global.h:274:24: note: 'sprintf' output between 15 and 67 bytes into a destination of size 15
  274 | #define Sprintf (void) sprintf
hacklib.c:1034:5: note: in expansion of macro 'Sprintf'
 1034 |     Sprintf(datestr, "%04ld%02d%02d%02d%02d%02d", datenum, lt->tm_mon + 1,
      |     ^~~~~~~

src/botl.c
src/do_name.c
src/dungeon.c
src/explode.c
src/hacklib.c

index 7a00673d55b43016fc02f52f13b8dabd8c768f5c..ff4e86be7d567c3d261763934267feae88a4de23 100644 (file)
@@ -3658,7 +3658,7 @@ choose_value:
                 Sprintf(mbuf, "\"%s\"", g.urole.rank[i].m);
                 if (g.urole.rank[i].f) {
                     Sprintf(fbuf, "\"%s\"", g.urole.rank[i].f);
-                    Sprintf(obuf, "%s or %s",
+                    Snprintf(obuf, sizeof obuf, "%s or %s",
                             flags.female ? fbuf : mbuf,
                             flags.female ? mbuf : fbuf);
                 } else {
index c78a5e1b2fe010490bf3af71702770b2667bc937..f7d353cd127ee644476d5c54dfe8841c695cb175 100644 (file)
@@ -591,7 +591,7 @@ getpos_menu(coord *ccp, int gloc)
                               &firstmatch, (struct permonst **)0)) {
             (void) coord_desc(garr[i].x, garr[i].y, tmpbuf,
                               iflags.getpos_coords);
-            Sprintf(fullbuf, "%s%s%s", firstmatch,
+            Snprintf(fullbuf, sizeof fullbuf, "%s%s%s", firstmatch,
                     (*tmpbuf ? " " : ""), tmpbuf);
             add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0,
                      ATR_NONE, fullbuf, MENU_ITEMFLAGS_NONE);
index c40e3f7e365c873fe358ff030305840ef21b4b8a..63d08c6666cf2e862d6831d3d9c01b81f41d587d 100644 (file)
@@ -66,7 +66,7 @@ static void traverse_mapseenchn(boolean, winid, int, int, int *);
 static const char *seen_string(xchar, const char *);
 static const char *br_string2(branch *);
 static const char *shop_string(int);
-static char *tunesuffix(mapseen *, char *);
+static char *tunesuffix(mapseen *, char *, size_t);
 
 #ifdef DEBUG
 #define DD g.dungeons[i]
@@ -2166,10 +2166,12 @@ print_dungeon(boolean bymenu, schar *rlev, xchar *rdgn)
         descr = unplaced ? "depth" : "level";
         nlev = dptr->num_dunlevs;
         if (nlev > 1)
-            Sprintf(buf, "%s: %s %d to %d", dptr->dname, makeplural(descr),
-                    dptr->depth_start, dptr->depth_start + nlev - 1);
+            Snprintf(buf, sizeof buf, "%s: %s %d to %d", dptr->dname,
+                     makeplural(descr), dptr->depth_start,
+                     dptr->depth_start + nlev - 1);
         else
-            Sprintf(buf, "%s: %s %d", dptr->dname, descr, dptr->depth_start);
+            Snprintf(buf, sizeof buf, "%s: %s %d", dptr->dname,
+                     descr, dptr->depth_start);
 
         /* Most entrances are uninteresting. */
         if (dptr->entry_lev != 1) {
@@ -3172,7 +3174,8 @@ shop_string(int rtype)
 /* if player knows about the mastermind tune, append it to Castle annotation;
    if drawbridge has been destroyed, flags.castletune will be zero */
 static char *
-tunesuffix(mapseen *mptr, char *outbuf)
+tunesuffix(mapseen *mptr, char *outbuf,
+           size_t bsz) /* sz of outbuf */
 {
     *outbuf = '\0';
     if (mptr->flags.castletune && u.uevent.uheard_tune) {
@@ -3182,7 +3185,7 @@ tunesuffix(mapseen *mptr, char *outbuf)
             Sprintf(tmp, "notes \"%s\"", g.tune);
         else
             Strcpy(tmp, "5-note tune");
-        Sprintf(outbuf, " (play %s to open or close drawbridge)", tmp);
+        Snprintf(outbuf, bsz, " (play %s to open or close drawbridge)", tmp);
     }
     return outbuf;
 }
@@ -3347,7 +3350,8 @@ print_mapseen(winid win, mapseen *mptr,
            indicates that the fort's entrance has been seen (or mapped) */
         Sprintf(buf, "%sFort Ludios.", PREFIX);
     } else if (mptr->flags.castle) {
-        Sprintf(buf, "%sThe castle%s.", PREFIX, tunesuffix(mptr, tmpbuf));
+        Snprintf(buf, sizeof buf, "%sThe castle%s.", PREFIX,
+                tunesuffix(mptr, tmpbuf, sizeof tmpbuf));
     } else if (mptr->flags.valley) {
         Sprintf(buf, "%sValley of the Dead.", PREFIX);
     } else if (mptr->flags.vibrating_square) {
index 27c7fad31e75b4c75cfae21b91451039e8d282b8..615ec3aaf290d15f405a73985a98b82fca271356 100644 (file)
@@ -538,8 +538,9 @@ explode(int x, int y,
                     g.killer.format = KILLED_BY_AN;
                 } else if (type >= 0 && olet != SCROLL_CLASS) {
                     g.killer.format = NO_KILLER_PREFIX;
-                    Sprintf(g.killer.name, "caught %sself in %s own %s", uhim(),
-                            uhis(), str);
+                    Snprintf(g.killer.name, sizeof g.killer.name,
+                             "caught %sself in %s own %s", uhim(),
+                             uhis(), str);
                 } else {
                     g.killer.format = (!strcmpi(str, "tower of flame")
                                      || !strcmpi(str, "fireball"))
index 17b52469c819171b1361a088f393c15af469bc7a..08e346d733835ce2bb5f307bfc24584766c8b3ba 100644 (file)
@@ -1031,8 +1031,9 @@ yyyymmddhhmmss(time_t date)
         datenum = (long) lt->tm_year + 2000L;
     else
         datenum = (long) lt->tm_year + 1900L;
-    Sprintf(datestr, "%04ld%02d%02d%02d%02d%02d", datenum, lt->tm_mon + 1,
-            lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec);
+    Snprintf(datestr, sizeof datestr, "%04ld%02d%02d%02d%02d%02d",
+             datenum, lt->tm_mon + 1,
+             lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec);
     debugpline1("yyyymmddhhmmss() produced date string %s", datestr);
     return datestr;
 }