compile-time format checking

We've had a few pull requests fixing format/argument mismatches
lately.  I did't notice when PRINTF_F(format_index,first_arg_index)
attribute use and the checking gcc and clang do with it got removed,
but that was very useful.  Putting it back triggers a whole bunch
of "format string is not literal" warnings, but that's because
'-Wformat-nonliteral' was explicitly added to the *.2020 hints.
Checking pline/You/&c arguments in the cases where the format is a
literal is more valuable than the complaints for sprintf being fed
a generated format, so reinstate PRINTF_F usage and turn off the
check for non-literal format strings.
This commit is contained in:
PatR
2021-11-26 21:50:44 -08:00
parent 2a7c2f25d7
commit 5224d85ad3
2 changed files with 25 additions and 25 deletions

View File

@@ -1,5 +1,5 @@
#------------------------------------------------------------------------------
# NetHack 3.7 compiler.2020 $NHDT-Date: 1597332785 2020/08/13 15:33:05 $ $NHDT-Branch: NetHack-3.7 $
# NetHack 3.7 compiler.2020 $NHDT-Date: 1637992237 2021/11/27 05:50:37 $ $NHDT-Branch: NetHack-3.7 $
# compiler flags: CCFLAGS is used to construct a value for CFLAGS with
# various -I, -D, and -W settings appended below;
@@ -47,7 +47,7 @@ CFLAGS+=-Wall -Wextra -Wno-missing-field-initializers \
-Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings
CFLAGS+=-pedantic
CFLAGS+=-Wmissing-declarations
CFLAGS+=-Wformat-nonliteral
CFLAGS+=-Wno-format-nonliteral
CFLAGS+=-Wunreachable-code
#
# the following are not allowed in C++
@@ -63,7 +63,7 @@ CCXXFLAGS+=-Wall -Wextra -Wno-missing-field-initializers \
-Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings
CCXXFLAGS+=-pedantic
CCXXFLAGS+=-Wmissing-declarations
CCXXFLAGS+=-Wformat-nonliteral
CCXXFLAGS+=-Wno-format-nonliteral
ifeq "$(CCISCLANG)" ""
# gcc-specific follows