From: nhmall Date: Wed, 3 Feb 2021 00:03:12 +0000 (-0500) Subject: enable -Wformat-nonliteral for linux and equivalent for windows compilers X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5b1d668c44e496abd87ed4ceb1596ad267d37f84;p=nethack 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’ --- diff --git a/include/warnings.h b/include/warnings.h index 01d10923f..8559f0d43 100644 --- a/include/warnings.h +++ b/include/warnings.h @@ -12,8 +12,11 @@ * When STDC_Pragma_AVAILABLE is not defined, these are defined as no-ops: * DISABLE_WARNING_UNREACHABLE_CODE * DISABLE_WARNING_CONDEXPR_IS_CONSTANT + * DISABLE_WARNING_FORMAT_NONLITERAL * ... * RESTORE_WARNINGS + * RESTORE_WARNING_CONDEXPR_IS_CONSTANT + * RESTORE_WARNING_FORMAT_NONLITERAL * */ @@ -34,8 +37,12 @@ #define DISABLE_WARNING_UNREACHABLE_CODE \ _Pragma("clang diagnostic push") \ _Pragma("clang diagnostic ignored \"-Wunreachable-code\"") +#define DISABLE_WARNING_FORMAT_NONLITERAL \ + _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Wformat-nonliteral\"") #define DISABLE_WARNING_CONDEXPR_IS_CONSTANT #define RESTORE_WARNING_CONDEXPR_IS_CONSTANT +#define RESTORE_WARNING_FORMAT_NONLITERAL _Pragma("clang diagnostic pop") #define RESTORE_WARNINGS _Pragma("clang diagnostic pop") #define STDC_Pragma_AVAILABLE @@ -44,8 +51,12 @@ #define DISABLE_WARNING_UNREACHABLE_CODE \ _Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic ignored \"-Wunreachable-code\"") +#define DISABLE_WARNING_FORMAT_NONLITERAL \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\"") #define DISABLE_WARNING_CONDEXPR_IS_CONSTANT #define RESTORE_WARNING_CONDEXPR_IS_CONSTANT +#define RESTORE_WARNING_FORMAT_NONLITERAL _Pragma("GCC diagnostic pop") #define RESTORE_WARNINGS _Pragma("GCC diagnostic pop") #define STDC_Pragma_AVAILABLE @@ -53,10 +64,14 @@ #define DISABLE_WARNING_UNREACHABLE_CODE \ _Pragma("warning( push )") \ _Pragma("warning( disable : 4702 )") +#define DISABLE_WARNING_FORMAT_NONLITERAL \ + _Pragma("warning( push )") \ + _Pragma("warning( disable : 4774 )") #define DISABLE_WARNING_CONDEXPR_IS_CONSTANT \ _Pragma("warning( push )") \ _Pragma("warning( disable : 4127 )") #define RESTORE_WARNING_CONDEXPR_IS_CONSTANT _Pragma("warning( pop )") +#define RESTORE_WARNING_FORMAT_NONLITERAL _Pragma("warning( pop )") #define RESTORE_WARNINGS _Pragma("warning( pop )") #define STDC_Pragma_AVAILABLE @@ -70,8 +85,10 @@ #if !defined(STDC_Pragma_AVAILABLE) #define DISABLE_WARNING_UNREACHABLE_CODE +#define DISABLE_WARNING_FORMAT_NONLITERAL #define DISABLE_WARNING_CONDEXPR_IS_CONSTANT #define RESTORE_WARNING_CONDEXPR_IS_CONSTANT +#define RESTORE_WARNING_FORMAT_NONLITERAL #define RESTORE_WARNINGS #endif diff --git a/src/attrib.c b/src/attrib.c index 6bc92b3c1..911d0ecc5 100644 --- a/src/attrib.c +++ b/src/attrib.c @@ -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) { diff --git a/src/cmd.c b/src/cmd.c index 75330355c..5abad96bb 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -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) { diff --git a/src/do.c b/src/do.c index b3e5530fb..fadc37ff8 100644 --- a/src/do.c +++ b/src/do.c @@ -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) diff --git a/src/do_name.c b/src/do_name.c index f7d353cd1..b1a9c61b1 100644 --- a/src/do_name.c +++ b/src/do_name.c @@ -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) { diff --git a/src/dungeon.c b/src/dungeon.c index 63d08c666..f789d266a 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -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 diff --git a/src/eat.c b/src/eat.c index 7bdb450a8..9a57cbf93 100644 --- a/src/eat.c +++ b/src/eat.c @@ -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) { diff --git a/src/end.c b/src/end.c index 28cb12a76..b71f0fb6a 100644 --- a/src/end.c +++ b/src/end.c @@ -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; diff --git a/src/engrave.c b/src/engrave.c index cfa81983f..f098b4607 100644 --- a/src/engrave.c +++ b/src/engrave.c @@ -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) { diff --git a/src/hacklib.c b/src/hacklib.c index 08e346d73..12c2006a6 100644 --- a/src/hacklib.c +++ b/src/hacklib.c @@ -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) diff --git a/src/insight.c b/src/insight.c index 2c8a36ce4..7df49eabe 100644 --- a/src/insight.c +++ b/src/insight.c @@ -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) diff --git a/src/invent.c b/src/invent.c index d44c41b71..9cd60dc40 100644 --- a/src/invent.c +++ b/src/invent.c @@ -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) diff --git a/src/light.c b/src/light.c index 60dd07e3e..273038b3e 100644 --- a/src/light.c +++ b/src/light.c @@ -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) diff --git a/src/mhitm.c b/src/mhitm.c index 9c396ff6c..e818ad97d 100644 --- a/src/mhitm.c +++ b/src/mhitm.c @@ -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 * diff --git a/src/options.c b/src/options.c index e45a17415..ab78f7400 100644 --- a/src/options.c +++ b/src/options.c @@ -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/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) { diff --git a/src/pager.c b/src/pager.c index 1897de794..436ce8c15 100644 --- a/src/pager.c +++ b/src/pager.c @@ -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) diff --git a/src/region.c b/src/region.c index 8bd10e5e3..b62257c9c 100644 --- a/src/region.c +++ b/src/region.c @@ -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) diff --git a/src/rumors.c b/src/rumors.c index a41447981..3adfc4432 100644 --- a/src/rumors.c +++ b/src/rumors.c @@ -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 * diff --git a/src/sounds.c b/src/sounds.c index a43ecb402..402a6b16a 100644 --- a/src/sounds.c +++ b/src/sounds.c @@ -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) diff --git a/src/spell.c b/src/spell.c index e20acfbe5..7cd1b4541 100644 --- a/src/spell.c +++ b/src/spell.c @@ -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) { diff --git a/src/timeout.c b/src/timeout.c index 47ea90490..47434ad7a 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -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) diff --git a/src/topten.c b/src/topten.c index 672ea348a..430cd39ea 100644 --- a/src/topten.c +++ b/src/topten.c @@ -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, diff --git a/src/windows.c b/src/windows.c index 002d5c54c..523421340 100644 --- a/src/windows.c +++ b/src/windows.c @@ -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; diff --git a/src/zap.c b/src/zap.c index 3b210789d..8b4694031 100644 --- a/src/zap.c +++ b/src/zap.c @@ -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) { diff --git a/sys/unix/hints/include/compiler.2020 b/sys/unix/hints/include/compiler.2020 index e8ab62fcc..07fca15c3 100755 --- a/sys/unix/hints/include/compiler.2020 +++ b/sys/unix/hints/include/compiler.2020 @@ -52,6 +52,7 @@ CFLAGS+=-Wimplicit-function-declaration CFLAGS+=-Wimplicit-int CFLAGS+=-Wmissing-declarations CFLAGS+=-Wmissing-prototypes +CFLAGS+=-Wformat-nonliteral ifeq "$(CCISCLANG)" "" #gcc-specific here CFLAGS+=-Wmissing-parameter-type diff --git a/sys/winnt/Makefile.msc b/sys/winnt/Makefile.msc index 3565f2570..6745afeaa 100644 --- a/sys/winnt/Makefile.msc +++ b/sys/winnt/Makefile.msc @@ -678,8 +678,10 @@ scall = # 4244 conversion possible loss of data # 4245 conversion from 'char' to 'uchar', signed/unsigned mismatch # 4100 unreferenced formal parameter +# 4774 format string is not a string literal (default is off at W4) +# #cflags = $(cflags:-W3=-W4) -wd4131 -wd4820 -wd4706 -wd4244 -wd4245 -wd4100 -cflags = $(cflags:-W3=-W4) -wd4820 -wd4706 -wd4244 -wd4245 -wd4100 -wd4310 +cflags = $(cflags:-W3=-W4) -wd4820 -wd4706 -wd4244 -wd4245 -wd4100 -wd4310 -w44774 !ENDIF #More verbose warning output options below diff --git a/util/makedefs.c b/util/makedefs.c index ed17b202b..733217498 100644 --- a/util/makedefs.c +++ b/util/makedefs.c @@ -337,6 +337,8 @@ do_makedefs(char *options) static char namebuf[1000]; +DISABLE_WARNING_FORMAT_NONLITERAL + static char * name_file(const char* template, const char* tag) { @@ -390,6 +392,8 @@ getfp(const char* template, const char* tag, const char* mode, int flg) return rv; } +RESTORE_WARNING_FORMAT_NONLITERAL + static boolean debug = FALSE; static FILE *inputfp; @@ -972,6 +976,8 @@ do_rnd_access_file(const char* fname, const char* deflt_content) return; } +DISABLE_WARNING_FORMAT_NONLITERAL + void do_rumors(void) { @@ -1064,6 +1070,8 @@ rumors_failure: exit(EXIT_FAILURE); } +RESTORE_WARNING_FORMAT_NONLITERAL + void do_date(void) { diff --git a/win/curses/cursstat.c b/win/curses/cursstat.c index 02aff4f58..65087675c 100644 --- a/win/curses/cursstat.c +++ b/win/curses/cursstat.c @@ -136,6 +136,8 @@ curses_status_finish(void) static int changed_fields = 0; +DISABLE_WARNING_FORMAT_NONLITERAL + void curses_status_update(int fldidx, genericptr_t ptr, int chg UNUSED, int percent, int color_and_attr, unsigned long *colormasks) @@ -202,6 +204,8 @@ curses_status_update(int fldidx, genericptr_t ptr, int chg UNUSED, int percent, } } +RESTORE_WARNING_FORMAT_NONLITERAL + static void draw_status(void) { @@ -981,6 +985,8 @@ curs_HPbar(char *text, /* pre-padded with trailing spaces if short */ extern const struct conditions_t conditions[]; /* botl.c */ extern int cond_idx[CONDITION_COUNT]; +DISABLE_WARNING_FORMAT_NONLITERAL + static void curs_stat_conds( int vert_cond, /* 0 => horizontal, 1 => vertical */ @@ -1104,6 +1110,8 @@ curs_stat_conds( return; } +RESTORE_WARNING_FORMAT_NONLITERAL + /* status_update() sets up values for horizontal status; do vertical */ void curs_vert_status_vals(int win_width) diff --git a/win/tty/wintty.c b/win/tty/wintty.c index 8a209dad6..4fbb855f2 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -3843,6 +3843,8 @@ tty_status_enablefield(int fieldidx, const char *nm, const char *fmt, * See doc/window.doc for more details. */ +DISABLE_WARNING_FORMAT_NONLITERAL + void tty_status_update(int fldidx, genericptr_t ptr, int chg UNUSED, int percent, int color, unsigned long *colormasks) @@ -3964,6 +3966,8 @@ tty_status_update(int fldidx, genericptr_t ptr, int chg UNUSED, int percent, return; } +RESTORE_WARNING_FORMAT_NONLITERAL + static int make_things_fit(boolean force_update) { diff --git a/win/win32/mswproc.c b/win/win32/mswproc.c index 4a5fb1987..60d65ff2a 100644 --- a/win/win32/mswproc.c +++ b/win/win32/mswproc.c @@ -3072,6 +3072,9 @@ status_update(int fldindex, genericptr_t ptr, int chg, int percent, int color, u longs telling which conditions should be displayed in each color and attriubte. */ + +DISABLE_WARNING_FORMAT_NONLITERAL + void mswin_status_update(int idx, genericptr_t ptr, int chg, int percent, int color, unsigned long *condmasks) { @@ -3173,3 +3176,5 @@ mswin_status_update(int idx, genericptr_t ptr, int chg, int percent, int color, } } +RESTORE_WARNING_FORMAT_NONLITERAL + diff --git a/win/win32/vs/NetHack.vcxproj b/win/win32/vs/NetHack.vcxproj index 02240e2c0..c2dd05dc4 100644 --- a/win/win32/vs/NetHack.vcxproj +++ b/win/win32/vs/NetHack.vcxproj @@ -29,7 +29,7 @@ - /Gs /Oi- %(AdditionalOptions) + /Gs /Oi- /w44774 %(AdditionalOptions) Disabled Default Speed @@ -43,7 +43,7 @@ - 4701;4702;4244;4310 + 4701;4702;4244;4310;4774 diff --git a/win/win32/vs/NetHackW.vcxproj b/win/win32/vs/NetHackW.vcxproj index f9c0319c6..98338781a 100644 --- a/win/win32/vs/NetHackW.vcxproj +++ b/win/win32/vs/NetHackW.vcxproj @@ -17,7 +17,7 @@ - /Gs /Oi- %(AdditionalOptions) + /Gs /Oi- /w44774 %(AdditionalOptions) Disabled true $(WinWin32Dir);$(IncDir);$(SysWinntDir);$(SysShareDir);$(WinShareDir);$(LuaDir);%(AdditionalIncludeDirectories) @@ -37,7 +37,7 @@ - 4701;4702;4244;4310 + 4701;4702;4244;4310;4774