]> granicus.if.org Git - nethack/commitdiff
fix two reported warnings with SERVER_ADMIN_MSG defined
authornhmall <nhmall@nethack.org>
Mon, 7 Feb 2022 14:16:31 +0000 (09:16 -0500)
committernhmall <nhmall@nethack.org>
Mon, 7 Feb 2022 14:16:31 +0000 (09:16 -0500)
Report stated a -Wformat-nonliteral at line 612,
and a -Wformat-security at line 614

I was only seeing the latter, so I added the former to the
flags in sys/unix/hints/include/compiler.370. Some compiler
versions have that warning on by default internally and others
don't. If the format string isn't a string literal, there's no
inteference with printf argument checking because that only
operates on string literals.

src/mail.c
sys/unix/hints/include/compiler.370

index 87ff8ada08ab7955bee7f207f0fe4594e0710895..417f88a1520762d38af5610972f2a1ea1bf69f9f 100644 (file)
@@ -559,6 +559,9 @@ ckmailstatus(void)
 }
 
 #if defined(SIMPLE_MAIL) || defined(SERVER_ADMIN_MSG)
+
+DISABLE_WARNING_FORMAT_NONLITERAL
+
 void
 read_simplemail(char *mbox, boolean adminmsg)
 {
@@ -611,7 +614,7 @@ read_simplemail(char *mbox, boolean adminmsg)
 
         pline(msgfrom, curline);
         if (adminmsg)
-            verbalize(msg);
+            verbalize("%s", msg);
         else
             pline("It reads: \"%s\".", msg);
 
@@ -642,6 +645,9 @@ read_simplemail(char *mbox, boolean adminmsg)
     if (!adminmsg)
         pline("It appears to be all gibberish.");
 }
+
+RESTORE_WARNING_FORMAT_NONLITERAL
+
 #endif /* SIMPLE_MAIL */
 
 void
index 08a759e61c47549e874caac595ae5b24fac657b3..36bf438ccf98538451783a5c28faef90f2a2cb61 100755 (executable)
@@ -56,6 +56,7 @@ CFLAGS+=-Wall -Wextra -Wno-missing-field-initializers \
 CFLAGS+=-pedantic
 CFLAGS+=-Wmissing-declarations
 CFLAGS+=-Wunreachable-code
+CFLAGS+=-Wformat-nonliteral
 #
 # the following are not allowed in C++
 CFLAGS+=-Wimplicit