From: Guy Harris Date: Mon, 27 Apr 2015 01:50:49 +0000 (-0700) Subject: Compile with -Wcast-qual. X-Git-Tag: tcpdump-4.8.0~271 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/a1fa7a0114659803bf12252b929621c9e5ad6df1 Compile with -Wcast-qual. That let me find what might have been the bulk of the 579(!) instances of "Deconst" reported in http://www.cl.cam.ac.uk/~dc552/papers/asplos15-memory-safe-c.pdf and, hopefully, will prevent more from creeping in. There are some remaining ones - and they represent attempts to overwrite the packet bytes handed to tcpdump by libpcap, which could well *fail* with, for example, memory-mapped capture mechanisms! --- diff --git a/aclocal.m4 b/aclocal.m4 index 285000d9..223f9384 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -947,6 +947,7 @@ AC_DEFUN(AC_LBL_DEVEL, AC_LBL_CHECK_COMPILER_OPT($1, -Wstrict-prototypes) AC_LBL_CHECK_COMPILER_OPT($1, -Wwrite-strings) AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-arith) + AC_LBL_CHECK_COMPILER_OPT($1, -Wcast-qual) AC_LBL_CHECK_COMPILER_OPT($1, -W) fi AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT() diff --git a/configure b/configure index 43b3068a..268d487a 100755 --- a/configure +++ b/configure @@ -7811,6 +7811,38 @@ 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 -Wcast-qual option" >&5 +$as_echo_n "checking whether the compiler supports the -Wcast-qual option... " >&6; } + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors -Wcast-qual" + 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 -Wcast-qual" + +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 + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -W option" >&5 $as_echo_n "checking whether the compiler supports the -W option... " >&6; } save_CFLAGS="$CFLAGS"