Create and use a snprintf wrapper in the core code

Use a wrapper around snprintf to consilidate all use, add
error checking, and remove gcc 9 warnings about not checking
the result.

Replace the prevous use of snprintf added to weapon.c with the
new scheme.

Update a second spot that has a gcc sprintf warning.  While
there, simplify the code.
This commit is contained in:
Dean Luick
2021-01-15 11:30:02 -06:00
parent 35f9115fae
commit 8143d55d76
4 changed files with 67 additions and 22 deletions

View File

@@ -1271,23 +1271,21 @@ enhance_weapon_skill()
(void) skill_level_name(i, sklnambuf);
if (wizard) {
if (!iflags.menu_tab_sep)
n = snprintf(buf, sizeof(buf), " %s%-*s %-12s %5d(%4d)", prefix,
longest, P_NAME(i), sklnambuf, P_ADVANCE(i),
practice_needed_to_advance(P_SKILL(i)));
Snprintf(buf, sizeof(buf), " %s%-*s %-12s %5d(%4d)", prefix,
longest, P_NAME(i), sklnambuf, P_ADVANCE(i),
practice_needed_to_advance(P_SKILL(i)));
else
n = snprintf(buf, sizeof(buf), " %s%s\t%s\t%5d(%4d)", prefix, P_NAME(i),
sklnambuf, P_ADVANCE(i),
practice_needed_to_advance(P_SKILL(i)));
Snprintf(buf, sizeof(buf), " %s%s\t%s\t%5d(%4d)", prefix, P_NAME(i),
sklnambuf, P_ADVANCE(i),
practice_needed_to_advance(P_SKILL(i)));
} else {
if (!iflags.menu_tab_sep)
n = snprintf(buf, sizeof(buf), " %s %-*s [%s]", prefix, longest,
P_NAME(i), sklnambuf);
Snprintf(buf, sizeof(buf), " %s %-*s [%s]", prefix, longest,
P_NAME(i), sklnambuf);
else
n = snprintf(buf, sizeof(buf), " %s%s\t[%s]", prefix, P_NAME(i),
sklnambuf);
Snprintf(buf, sizeof(buf), " %s%s\t[%s]", prefix, P_NAME(i),
sklnambuf);
}
if (n >= sizeof(buf)) /* check for overflow */
buf[sizeof(buf)-1] = 0; /* terminate string */
any.a_int = can_advance(i, speedy) ? i + 1 : 0;
add_menu(win, &nul_glyphinfo, &any, 0, 0,
ATR_NONE, buf, MENU_ITEMFLAGS_NONE);