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 [-
2147483647,
2147483646]
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 [-
2147483647,
2147483647]
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,
| ^~~~~~~
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 {
&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);
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]
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) {
/* 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) {
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;
}
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) {
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"))
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;
}