]> The Tcpdump Group git mirrors - libpcap/commitdiff
Add -Wformat-nonliteral and fix most warnings that come up 710/head
authorJoerg Mayer <[email protected]>
Wed, 2 May 2018 06:11:16 +0000 (08:11 +0200)
committerJoerg Mayer <[email protected]>
Thu, 3 May 2018 19:16:35 +0000 (21:16 +0200)
The remaining ocurrences are genuine and intentional.

warning: format string is not a string literal [-Wformat-nonliteral]

CMakeLists.txt
aclocal.m4
configure
optimize.c
testprogs/can_set_rfmon_test.c
testprogs/reactivatetest.c

index ed675148f044ac1b8e5ddce91a8ee1bd3e32a3bb..fbc452e7a1b31a3973e0a0e527e484afee196a1b 100644 (file)
@@ -1676,6 +1676,7 @@ if(EXISTS ${CMAKE_SOURCE_DIR}/.devel OR EXISTS ${CMAKE_BINARY_DIR}/.devel)
         # check_and_add_compiler_option(-Wcovered-switch-default)
         check_and_add_compiler_option(-Wmissing-variable-declarations)
        check_and_add_compiler_option(-Wunused-parameter)
+       check_and_add_compiler_option(-Wformat-nonliteral)
     endif()
 endif()
 
index 0300cf74240b0c41689f80dbbba95b94f6ee6edf..7f5ca9aa6ca734bada1a53c2f88102f1fbfb713b 100644 (file)
@@ -855,6 +855,7 @@ AC_DEFUN(AC_LBL_DEVEL,
                    # AC_LBL_CHECK_COMPILER_OPT($1, -Wcovered-switch-default)
                    AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-variable-declarations)
                    AC_LBL_CHECK_COMPILER_OPT($1, -Wunused-parameter)
+                   AC_LBL_CHECK_COMPILER_OPT($1, -Wformat-nonliteral)
            fi
            AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT()
            #
index eb6c8f90eb190032f344f7bf8ac69c154c201b30..1b2408cdd78d567913b28b0c1acd57ad509d4d8a 100755 (executable)
--- a/configure
+++ b/configure
@@ -8917,6 +8917,49 @@ else
 $as_echo "no" >&6; }
                CFLAGS="$save_CFLAGS"
 
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -Wformat-nonliteral option" >&5
+$as_echo_n "checking whether the compiler supports the -Wformat-nonliteral option... " >&6; }
+       save_CFLAGS="$CFLAGS"
+       if expr "x-Wformat-nonliteral" : "x-W.*" >/dev/null
+       then
+           CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -Wformat-nonliteral"
+       elif expr "x-Wformat-nonliteral" : "x-f.*" >/dev/null
+       then
+           CFLAGS="$CFLAGS -Werror -Wformat-nonliteral"
+       elif expr "x-Wformat-nonliteral" : "x-m.*" >/dev/null
+       then
+           CFLAGS="$CFLAGS -Werror -Wformat-nonliteral"
+       else
+           CFLAGS="$CFLAGS -Wformat-nonliteral"
+       fi
+       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+return 0
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+               CFLAGS="$save_CFLAGS"
+               V_CCOPT="$V_CCOPT -Wformat-nonliteral"
+
+else
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+               CFLAGS="$save_CFLAGS"
+
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
index 2f578ce1a84b9f3d68189e3a1e488ba9430847ac..86dcbeef5fe839d2d29dc40e25e4c3cf036c6f82 100644 (file)
@@ -2187,7 +2187,7 @@ convert_code_r(compiler_state_t *cstate, conv_state_t *conv_state,
            {
                u_int i;
                int jt, jf;
-               const char *ljerr = "%s for block-local relative jump: off=%d";
+               const char ljerr[] = "%s for block-local relative jump: off=%d";
 
 #if 0
                printf("code=%x off=%d %x %x\n", src->s.code,
index c6fe103735c96d2ee1018a6af79126d1a7d98c1f..f6188ba1399e334897619b8264ca95eb55677bf1 100644 (file)
@@ -39,7 +39,7 @@ The Regents of the University of California.  All rights reserved.\n";
 static const char *program_name;
 
 /* Forwards */
-static void PCAP_NORETURN error(const char *, ...);
+static void PCAP_NORETURN error(PCAP_FORMAT_STRING(const char *), ...) PCAP_PRINTFLIKE(1,2);
 
 int
 main(int argc, char **argv)
index 168b809b323230faf306cbaafc315b81017cec42..d7f3e322c1753a2d24d4d19146c6c4886f77cefd 100644 (file)
@@ -36,7 +36,7 @@ The Regents of the University of California.  All rights reserved.\n";
 #include "pcap/funcattrs.h"
 
 /* Forwards */
-static void PCAP_NORETURN error(const char *, ...);
+static void PCAP_NORETURN error(PCAP_FORMAT_STRING(const char *), ...) PCAP_PRINTFLIKE(1,2);
 
 int
 main(void)