From: Joerg Mayer Date: Wed, 2 May 2018 06:11:16 +0000 (+0200) Subject: Add -Wformat-nonliteral and fix most warnings that come up X-Git-Tag: libpcap-1.9-bp~44^2 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/3a9d409d7510e3be9cb90ac2ce8b6450e19157dd Add -Wformat-nonliteral and fix most warnings that come up The remaining ocurrences are genuine and intentional. warning: format string is not a string literal [-Wformat-nonliteral] --- diff --git a/CMakeLists.txt b/CMakeLists.txt index ed675148..fbc452e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/aclocal.m4 b/aclocal.m4 index 0300cf74..7f5ca9aa 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -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() # diff --git a/configure b/configure index eb6c8f90..1b2408cd 100755 --- 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 diff --git a/optimize.c b/optimize.c index 2f578ce1..86dcbeef 100644 --- a/optimize.c +++ b/optimize.c @@ -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, diff --git a/testprogs/can_set_rfmon_test.c b/testprogs/can_set_rfmon_test.c index c6fe1037..f6188ba1 100644 --- a/testprogs/can_set_rfmon_test.c +++ b/testprogs/can_set_rfmon_test.c @@ -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) diff --git a/testprogs/reactivatetest.c b/testprogs/reactivatetest.c index 168b809b..d7f3e322 100644 --- a/testprogs/reactivatetest.c +++ b/testprogs/reactivatetest.c @@ -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)