Fix gcc sprintf warnings

Gcc 9 has become more vocal with sprintf buffer overflow
checking.  Remove these sprintf warnings by changing the
offending calls to a snprintf wrapper that will explicitly
check the result.
This commit is contained in:
Dean Luick
2021-01-08 20:33:39 -06:00
parent 8143d55d76
commit 3ef0f889e6
17 changed files with 97 additions and 76 deletions

View File

@@ -1425,7 +1425,8 @@ int how;
switch (obj->otyp) {
case POT_WATER:
Sprintf(saddle_glows, "%s %s", buf, aobjnam(saddle, "glow"));
Snprintf(saddle_glows, sizeof(saddle_glows), "%s %s",
buf, aobjnam(saddle, "glow"));
affected = H2Opotion_dip(obj, saddle, useeit, saddle_glows);
break;
case POT_POLYMORPH:
@@ -1975,8 +1976,8 @@ dodip()
here = levl[u.ux][u.uy].typ;
/* Is there a fountain to dip into here? */
if (IS_FOUNTAIN(here)) {
Sprintf(qbuf, "%s%s into the fountain?", Dip_,
flags.verbose ? obuf : shortestname);
Snprintf(qbuf, sizeof(qbuf), "%s%s into the fountain?", Dip_,
flags.verbose ? obuf : shortestname);
/* "Dip <the object> into the fountain?" */
if (yn(qbuf) == 'y') {
dipfountain(obj);
@@ -1985,8 +1986,8 @@ dodip()
} else if (is_pool(u.ux, u.uy)) {
const char *pooltype = waterbody_name(u.ux, u.uy);
Sprintf(qbuf, "%s%s into the %s?", Dip_,
flags.verbose ? obuf : shortestname, pooltype);
Snprintf(qbuf, sizeof(qbuf), "%s%s into the %s?", Dip_,
flags.verbose ? obuf : shortestname, pooltype);
/* "Dip <the object> into the {pool, moat, &c}?" */
if (yn(qbuf) == 'y') {
if (Levitation) {
@@ -2005,7 +2006,8 @@ dodip()
}
/* "What do you want to dip <the object> into? [xyz or ?*] " */
Sprintf(qbuf, "dip %s into", flags.verbose ? obuf : shortestname);
Snprintf(qbuf, sizeof(qbuf), "dip %s into",
flags.verbose ? obuf : shortestname);
potion = getobj(qbuf, drink_ok, GETOBJ_NOFLAGS);
if (!potion)
return 0;