enable -Wformat-nonliteral for linux and equivalent for windows compilers

Whitelist all the verified existing triggers:
makedefs.c: In function ‘name_file’
attrib.c: one compiler balks at a ? b : c for fmtstring
cmd.c: In function ‘extcmd_via_menu’
cmd.c: In function ‘wiz_levltyp_legend’
do.c: In function ‘goto_level’
do_name.c: In function ‘coord_desc’
dungeon.c: In function ‘overview_stats’
eat.c:  one compiler balks at a ? b : c for fmtstring
end.c:  one compiler balks at a ? b : c for fmtstring
engrave.c: In function ‘engr_stats’
hack:c one compiler balks at a ? b : c for fmtstring
hacklib.c: one compiler balks at a ? b : c for fmtstring
insight.c: one compiler balks at a ? b : c for fmtstring
invent.c: In function ‘let_to_name’
light.c: In function ‘light_stats’
mhitm.c: In function ‘missmm’
options.c: In function ‘handler_symset’
options.c: In function ‘basic_menu_colors’
options.c: In function ‘optfn_o_autopickup_exceptions’
options.c: In function ‘optfn_o_menu_colors’
options.c: In function ‘optfn_o_message_types’
options.c: In function ‘optfn_o_status_cond’
options.c: In function ‘optfn_o_status_hilites’
options.c: In function ‘doset’
options.c: In function ‘doset_add_menu’
options.c: In function ‘show_menu_controls’
options.c: In function ‘handle_add_list_remove’
pager.c: In function ‘do_supplemental_info’
pager.c: In function ‘dohelp’
region.c: In function ‘region_stats’
rumors.c: sscanf usage
sounds.c: In function ‘domonnoise’
spell.c: In function ‘dospellmenu’
timeout.c: In function ‘timer_stats’
topten.c: In function ‘outentry’, fscanf, sscanf, fprintf usage
windows.c: In function ‘genl_status_update’
zap.c: one compiler balks at a ? b : c for fmtstring
win/curses/cursstat.c: In function ‘curses_status_update’
win/tty/wintty.c: In function ‘tty_status_update’
win/win32/mswproc.c: In function ‘mswin_status_update’
This commit is contained in:
nhmall
2021-02-02 19:03:12 -05:00
parent d79365c6b0
commit 5b1d668c44
32 changed files with 195 additions and 5 deletions

View File

@@ -799,6 +799,8 @@ is_innate(int propidx)
return FROM_NONE;
}
DISABLE_WARNING_FORMAT_NONLITERAL
char *
from_what(int propidx) /* special cases can have negative values */
{
@@ -891,6 +893,8 @@ from_what(int propidx) /* special cases can have negative values */
return buf;
}
RESTORE_WARNING_FORMAT_NONLITERAL
void
adjabil(int oldlevel, int newlevel)
{

View File

@@ -551,6 +551,8 @@ doextlist(void)
#if defined(TTY_GRAPHICS) || defined(CURSES_GRAPHICS)
#define MAX_EXT_CMD 200 /* Change if we ever have more ext cmds */
DISABLE_WARNING_FORMAT_NONLITERAL
/*
* This is currently used only by the tty interface and is
* controlled via runtime option 'extmenu'. (Most other interfaces
@@ -692,6 +694,9 @@ extcmd_via_menu(void)
}
return ret;
}
RESTORE_WARNING_FORMAT_NONLITERAL
#endif /* TTY_GRAPHICS */
/* #monster command - use special monster ability while polymorphed */
@@ -1457,6 +1462,8 @@ levltyp_to_name(int typ)
return NULL;
}
DISABLE_WARNING_FORMAT_NONLITERAL
/* explanation of base-36 output from wiz_map_levltyp() */
static void
wiz_levltyp_legend(void)
@@ -1497,6 +1504,8 @@ wiz_levltyp_legend(void)
return;
}
RESTORE_WARNING_FORMAT_NONLITERAL
DISABLE_WARNING_CONDEXPR_IS_CONSTANT
/* #wizsmell command - test usmellmon(). */
@@ -1541,6 +1550,8 @@ wiz_smell(void)
RESTORE_WARNING_CONDEXPR_IS_CONSTANT
DISABLE_WARNING_FORMAT_NONLITERAL
#define DEFAULT_TIMEOUT_INCR 30
/* #wizinstrinsic command to set some intrinsics for testing */
@@ -1695,6 +1706,8 @@ wiz_intrinsic(void)
return 0;
}
RESTORE_WARNING_FORMAT_NONLITERAL
/* #wizrumorcheck command - verify each rumor access */
static int
wiz_rumor_check(void)
@@ -2589,6 +2602,8 @@ count_obj(struct obj *chain, long *total_count, long *total_size,
*total_size += size;
}
DISABLE_WARNING_FORMAT_NONLITERAL /* RESTORE_WARNING follows show_wiz_stats */
static void
obj_chain(winid win, const char *src, struct obj *chain, boolean force,
long *total_count, long *total_size)
@@ -2905,6 +2920,8 @@ wiz_show_stats(void)
return 0;
}
RESTORE_WARNING_FORMAT_NONLITERAL
void
sanity_check(void)
{

View File

@@ -1232,6 +1232,8 @@ u_collide_m(struct monst *mtmp)
}
}
DISABLE_WARNING_FORMAT_NONLITERAL
void
goto_level(d_level *newlevel, boolean at_stairs, boolean falling, boolean portal)
{
@@ -1730,6 +1732,8 @@ goto_level(d_level *newlevel, boolean at_stairs, boolean falling, boolean portal
(void) pickup(1);
}
RESTORE_WARNING_FORMAT_NONLITERAL
/* usually called from goto_level(); might be called from Sting_effects() */
void
maybe_lvltport_feedback(void)

View File

@@ -96,6 +96,8 @@ getpos_help_keyxhelp(winid tmpwin, const char *k1, const char *k2, int gloc)
putstr(tmpwin, 0, sbuf);
}
DISABLE_WARNING_FORMAT_NONLITERAL
/* the response for '?' help request in getpos() */
static void
getpos_help(boolean force, const char *goal)
@@ -225,6 +227,8 @@ getpos_help(boolean force, const char *goal)
destroy_nhwindow(tmpwin);
}
RESTORE_WARNING_FORMAT_NONLITERAL
static int QSORTCALLBACK
cmp_coord_distu(const void *a, const void *b)
{
@@ -486,6 +490,8 @@ dxdy_to_dist_descr(int dx, int dy, boolean fulldir)
return buf;
}
DISABLE_WARNING_FORMAT_NONLITERAL
/* coordinate formatting for 'whatis_coord' option */
char *
coord_desc(int x, int y, char *outbuf, char cmode)
@@ -527,6 +533,8 @@ coord_desc(int x, int y, char *outbuf, char cmode)
return outbuf;
}
RESTORE_WARNING_FORMAT_NONLITERAL
static void
auto_describe(int cx, int cy)
{

View File

@@ -2517,6 +2517,8 @@ load_mapseen(NHFILE *nhfp)
return load;
}
DISABLE_WARNING_FORMAT_NONLITERAL
/* to support '#stats' wizard-mode command */
void
overview_stats(winid win, const char *statsfmt,
@@ -2559,6 +2561,8 @@ overview_stats(winid win, const char *statsfmt,
*total_size += osize + bsize + asize;
}
RESTORE_WARNING_FORMAT_NONLITERAL
/* Remove all mapseen objects for a particular dnum.
* Useful during quest expulsion to remove quest levels.
* [No longer deleted, just marked as unreachable. #overview will

View File

@@ -915,6 +915,8 @@ givit(int type, register struct permonst *ptr)
}
}
DISABLE_WARNING_FORMAT_NONLITERAL
/* called after completely consuming a corpse */
static void
cpostfx(int pm)
@@ -1142,6 +1144,8 @@ cpostfx(int pm)
return;
}
RESTORE_WARNING_FORMAT_NONLITERAL
void
violated_vegetarian(void)
{

View File

@@ -385,6 +385,9 @@ done_hangup(int sig)
#endif
#endif /* NO_SIGNAL */
DISABLE_WARNING_FORMAT_NONLITERAL /* one compiler warns if the format
string is the result of a ? x : y */
void
done_in_by(struct monst *mtmp, int how)
{
@@ -504,6 +507,8 @@ done_in_by(struct monst *mtmp, int how)
return;
}
RESTORE_WARNING_FORMAT_NONLITERAL
/* some special cases for overriding while-helpless reason */
static const struct {
int why, unmulti;

View File

@@ -1234,6 +1234,8 @@ rest_engravings(NHFILE *nhfp)
}
}
DISABLE_WARNING_FORMAT_NONLITERAL
/* to support '#stats' wizard-mode command */
void
engr_stats(const char *hdrfmt, char *hdrbuf, long *count, long *size)
@@ -1248,6 +1250,8 @@ engr_stats(const char *hdrfmt, char *hdrbuf, long *count, long *size)
}
}
RESTORE_WARNING_FORMAT_NONLITERAL
void
del_engr(register struct engr *ep)
{

View File

@@ -572,6 +572,9 @@ ordin(int n) /* note: should be non-negative */
: (dd == 1) ? "st" : (dd == 2) ? "nd" : "rd";
}
DISABLE_WARNING_FORMAT_NONLITERAL /* one compiler complains about
result of ?: for format string */
/* make a signed digit string from a number */
char *
sitoa(int n)
@@ -582,6 +585,8 @@ sitoa(int n)
return buf;
}
RESTORE_WARNING_FORMAT_NONLITERAL
/* return the sign of a number: -1, 0, or 1 */
int
sgn(int n)

View File

@@ -2316,6 +2316,8 @@ dovanquished(void)
return 0;
}
DISABLE_WARNING_FORMAT_NONLITERAL
/* #wizborn extended command */
int
doborn(void)
@@ -2349,6 +2351,8 @@ doborn(void)
return 0;
}
RESTORE_WARNING_FORMAT_NONLITERAL
/* high priests aren't unique but are flagged as such to simplify something */
#define UniqCritterIndx(mndx) ((mons[mndx].geno & G_UNIQ) \
&& mndx != PM_HIGH_CLERIC)

View File

@@ -2320,6 +2320,8 @@ prinv(const char *prefix, struct obj *obj, long quan)
xprname(obj, (char *) 0, obj_to_let(obj), TRUE, 0L, quan));
}
DISABLE_WARNING_FORMAT_NONLITERAL
char *
xprname(struct obj *obj,
const char *txt, /* text to print instead of obj */
@@ -2365,6 +2367,8 @@ xprname(struct obj *obj,
return li;
}
RESTORE_WARNING_FORMAT_NONLITERAL
/* the 'i' command */
int
ddoinv(void)
@@ -3781,6 +3785,8 @@ static NEARDATA const char *names[] = {
static NEARDATA const char oth_symbols[] = { CONTAINED_SYM, '\0' };
static NEARDATA const char *oth_names[] = { "Bagged/Boxed items" };
DISABLE_WARNING_FORMAT_NONLITERAL
char *
let_to_name(char let, boolean unpaid, boolean showsym)
{
@@ -3823,6 +3829,8 @@ let_to_name(char let, boolean unpaid, boolean showsym)
return g.invbuf;
}
RESTORE_WARNING_FORMAT_NONLITERAL
/* release the static buffer used by let_to_name() */
void
free_invbuf(void)

View File

@@ -436,6 +436,8 @@ restore_light_sources(NHFILE *nhfp)
}
}
DISABLE_WARNING_FORMAT_NONLITERAL
/* to support '#stats' wizard-mode command */
void
light_stats(const char *hdrfmt, char *hdrbuf, long *count, long *size)
@@ -450,6 +452,8 @@ light_stats(const char *hdrfmt, char *hdrbuf, long *count, long *size)
}
}
RESTORE_WARNING_FORMAT_NONLITERAL
/* Relink all lights that are so marked. */
void
relink_light_sources(boolean ghostly)

View File

@@ -71,6 +71,8 @@ pre_mm_attack(struct monst *magr, struct monst *mdef)
}
}
DISABLE_WARNING_FORMAT_NONLITERAL
static
void
missmm(register struct monst *magr, register struct monst *mdef,
@@ -91,6 +93,8 @@ missmm(register struct monst *magr, register struct monst *mdef,
noises(magr, mattk);
}
RESTORE_WARNING_FORMAT_NONLITERAL
/*
* fightm() -- fight some other monster
*

View File

@@ -4849,6 +4849,8 @@ handler_whatis_filter(void)
return optn_ok;
}
DISABLE_WARNING_FORMAT_NONLITERAL
static int
handler_symset(int optidx)
{
@@ -5026,6 +5028,8 @@ handler_symset(int optidx)
return optidx;
}
RESTORE_WARNING_FORMAT_NONLITERAL
static int
handler_autopickup_exception(void)
{
@@ -6150,6 +6154,8 @@ match_str2attr(const char *str, boolean complain)
extern const char regex_id[]; /* from sys/share/<various>regex.{c,cpp} */
DISABLE_WARNING_FORMAT_NONLITERAL
/* True: temporarily replace menu color entries with a fake set of menu
colors, { "light blue"=light_blue, "blue"=blue, "red"=red, &c }, that
illustrates most colors for use when the pick-a-color menu is rendered;
@@ -6203,6 +6209,8 @@ basic_menu_colors(boolean load_colors)
}
}
RESTORE_WARNING_FORMAT_NONLITERAL
int
query_color(const char *prompt)
{
@@ -6970,6 +6978,8 @@ static char fmtstr_doset[] = "%s%-15s [%s] ";
static char fmtstr_doset_tab[] = "%s\t[%s]";
static char n_currently_set[] = "(%d currently set)";
DISABLE_WARNING_FORMAT_NONLITERAL /* RESTORE is after show_menucontrols() */
static int
optfn_o_autopickup_exceptions(int optidx UNUSED, int req, boolean negated UNUSED,
char *opts, char *op UNUSED)
@@ -7340,6 +7350,7 @@ doset_add_menu(winid win, /* window to add to */
ATR_NONE, buf, MENU_ITEMFLAGS_NONE);
}
/* display keys for menu actions; used by cmd.c '?i' and pager.c '?k' */
void
show_menu_controls(winid win, boolean dolist)
@@ -7431,6 +7442,9 @@ show_menu_controls(winid win, boolean dolist)
arg = "";
}
}
RESTORE_WARNING_FORMAT_NONLITERAL
static int
count_cond(void)
{
@@ -7457,6 +7471,8 @@ count_apes(void)
return numapes;
}
DISABLE_WARNING_FORMAT_NONLITERAL
/* common to msg-types, menu-colors, autopickup-exceptions */
static int
handle_add_list_remove(const char *optname, int numtotal)
@@ -7504,6 +7520,8 @@ handle_add_list_remove(const char *optname, int numtotal)
return opt_idx;
}
RESTORE_WARNING_FORMAT_NONLITERAL
int
dotogglepickup(void)
{

View File

@@ -1425,6 +1425,8 @@ do_look(int mode, coord *click_cc)
return 0;
}
DISABLE_WARNING_FORMAT_NONLITERAL /* RESTORE is after do_supplemental_info() */
static void
look_all(boolean nearby, /* True => within BOLTLIM, False => entire map */
boolean do_mons) /* True => monsters, False => objects */
@@ -1600,6 +1602,8 @@ do_supplemental_info(char *name, struct permonst *pm, boolean without_asking)
}
}
RESTORE_WARNING_FORMAT_NONLITERAL
/* the '/' command */
int
dowhatis(void)
@@ -2098,6 +2102,8 @@ static const struct {
{ (void (*)(void)) 0, (char *) 0 }
};
DISABLE_WARNING_FORMAT_NONLITERAL
/* the '?' command */
int
dohelp(void)
@@ -2135,6 +2141,8 @@ dohelp(void)
return 0;
}
RESTORE_WARNING_FORMAT_NONLITERAL
/* the 'V' command; also a choice for '?' */
int
dohistory(void)

View File

@@ -802,6 +802,8 @@ rest_regions(NHFILE* nhfp)
reset_region_mids(g.regions[i]);
}
DISABLE_WARNING_FORMAT_NONLITERAL
/* to support '#stats' wizard-mode command */
void
region_stats(const char* hdrfmt, char* hdrbuf, long* count, long* size)
@@ -825,6 +827,8 @@ region_stats(const char* hdrfmt, char* hdrbuf, long* count, long* size)
/* ? */
}
RESTORE_WARNING_FORMAT_NONLITERAL
/* update monster IDs for region being loaded from bones; `ghostly' implied */
static void
reset_region_mids(NhRegion* reg)

View File

@@ -45,6 +45,8 @@ static void init_oracles(dlb *);
static void others_check(const char *ftype, const char *, winid *);
static void couldnt_open_file(const char *);
DISABLE_WARNING_FORMAT_NONLITERAL
static void
init_rumors(dlb* fp)
{
@@ -70,6 +72,8 @@ init_rumors(dlb* fp)
}
}
RESTORE_WARNING_FORMAT_NONLITERAL
/* exclude_cookie is a hack used because we sometimes want to get rumors in a
* context where messages such as "You swallowed the fortune!" that refer to
* cookies should not appear. This has no effect for true rumors since none
@@ -272,6 +276,8 @@ rumor_check(void)
}
}
DISABLE_WARNING_FORMAT_NONLITERAL
/* 3.7: augments rumors_check(); test 'engrave' or 'epitaph' or 'bogusmon' */
static void
others_check(const char* ftype, const char* fname, winid* winptr)
@@ -373,6 +379,8 @@ others_check(const char* ftype, const char* fname, winid* winptr)
}
}
RESTORE_WARNING_FORMAT_NONLITERAL
/* Gets a random line of text from file 'fname', and returns it.
rng is the random number generator to use, and should act like rn2 does. */
char *

View File

@@ -548,6 +548,8 @@ mon_is_gecko(struct monst* mon)
return (boolean) (glyph_to_mon(glyph) == PM_GECKO);
}
DISABLE_WARNING_FORMAT_NONLITERAL
static int
domonnoise(register struct monst* mtmp)
{
@@ -1048,6 +1050,8 @@ domonnoise(register struct monst* mtmp)
return 1;
}
RESTORE_WARNING_FORMAT_NONLITERAL
/* #chat command */
int
dotalk(void)

View File

@@ -337,6 +337,8 @@ book_cursed(struct obj* book)
stop_occupation();
}
DISABLE_WARNING_FORMAT_NONLITERAL
static int
learn(void)
{
@@ -435,6 +437,8 @@ learn(void)
return 0;
}
RESTORE_WARNING_FORMAT_NONLITERAL
int
study_book(register struct obj* spellbook)
{
@@ -1628,6 +1632,8 @@ dovspell(void)
return 0;
}
DISABLE_WARNING_FORMAT_NONLITERAL
static boolean
dospellmenu(
const char *prompt,
@@ -1712,6 +1718,8 @@ dospellmenu(
return FALSE;
}
RESTORE_WARNING_FORMAT_NONLITERAL
static int
percent_success(int spell)
{

View File

@@ -2377,6 +2377,8 @@ restore_timers(NHFILE* nhfp, int range, long adjust)
}
}
DISABLE_WARNING_FORMAT_NONLITERAL
/* to support '#stats' wizard-mode command */
void
timer_stats(const char* hdrfmt, char *hdrbuf, long *count, long *size)
@@ -2391,6 +2393,8 @@ timer_stats(const char* hdrfmt, char *hdrbuf, long *count, long *size)
}
}
RESTORE_WARNING_FORMAT_NONLITERAL
/* reset all timers that are marked for reseting */
void
relink_timers(boolean ghostly)

View File

@@ -205,6 +205,8 @@ discardexcess(FILE* rfile)
} while (c != '\n' && c != EOF);
}
DISABLE_WARNING_FORMAT_NONLITERAL
static void
readentry(FILE* rfile, struct toptenentry* tt)
{
@@ -320,6 +322,8 @@ writeentry(FILE* rfile, struct toptenentry* tt)
#endif
}
RESTORE_WARNING_FORMAT_NONLITERAL
#ifdef XLOGFILE
/* as tab is never used in eg. g.plname or death, no need to mangle those. */
@@ -908,6 +912,8 @@ outheader(void)
topten_print(linebuf);
}
DISABLE_WARNING_FORMAT_NONLITERAL
/* so>0: standout line; so=0: ordinary line */
static void
outentry(int rank, struct toptenentry* t1, boolean so)
@@ -1069,6 +1075,8 @@ outentry(int rank, struct toptenentry* t1, boolean so)
topten_print(linebuf);
}
RESTORE_WARNING_FORMAT_NONLITERAL
static int
score_wanted(
boolean current_ver,

View File

@@ -888,6 +888,8 @@ genl_status_enablefield(int fieldidx, const char *nm, const char *fmt,
status_activefields[fieldidx] = enable;
}
DISABLE_WARNING_FORMAT_NONLITERAL
/* call once for each field, then call with BL_FLUSH to output the result */
void
genl_status_update(int idx, genericptr_t ptr, int chg UNUSED,
@@ -1068,6 +1070,8 @@ genl_status_update(int idx, genericptr_t ptr, int chg UNUSED,
putmixed(WIN_STATUS, 0, newbot2); /* putmixed() due to GOLD glyph */
}
RESTORE_WARNING_FORMAT_NONLITERAL
static struct window_procs dumplog_windowprocs_backup;
static FILE *dumplog_file;

View File

@@ -5256,6 +5256,8 @@ resist(struct monst *mtmp, char oclass, int damage, int tell)
#define MAXWISHTRY 5
DISABLE_WARNING_FORMAT_NONLITERAL
static void
wishcmdassist(int triesleft)
{
@@ -5313,6 +5315,8 @@ wishcmdassist(int triesleft)
destroy_nhwindow(win);
}
RESTORE_WARNING_FORMAT_NONLITERAL
void
makewish(void)
{