From: Joerg Mayer Date: Wed, 28 Mar 2018 22:32:06 +0000 (-0700) Subject: Add -Wmissing-noreturn to compiler warnings and fix all fixable warnings. X-Git-Tag: libpcap-1.9-bp~161 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/c6fde3d1975ecda5563c39712ff389e78e50b895 Add -Wmissing-noreturn to compiler warnings and fix all fixable warnings. Also suppress the one non-fixable warning: build/scanner.c:5020:1: warning: function 'yy_fatal_error' could be declared with attribute 'noreturn' [-Wmissing-noreturn] Signed-off-by: Joerg Mayer --- diff --git a/CMakeLists.txt b/CMakeLists.txt index ba2244ec..16211ac4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1671,6 +1671,7 @@ if(EXISTS ${CMAKE_SOURCE_DIR}/.devel OR EXISTS ${CMAKE_BINARY_DIR}/.devel) check_and_add_compiler_option(-Wused-but-marked-unused) check_and_add_compiler_option(-Wdocumentation) check_and_add_compiler_option(-Wcomma) + check_and_add_compiler_option(-Wmissing-noreturn) endif() endif() diff --git a/aclocal.m4 b/aclocal.m4 index 788b20a8..f4dd40ca 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -849,6 +849,7 @@ AC_DEFUN(AC_LBL_DEVEL, AC_LBL_CHECK_COMPILER_OPT($1, -Wused-but-marked-unused) AC_LBL_CHECK_COMPILER_OPT($1, -Wdocumentation) AC_LBL_CHECK_COMPILER_OPT($1, -Wcomma) + AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-noreturn) fi AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT() # diff --git a/configure b/configure index e60d7f5a..1eb5ad35 100755 --- a/configure +++ b/configure @@ -8776,6 +8776,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 -Wmissing-noreturn option" >&5 +$as_echo_n "checking whether the compiler supports the -Wmissing-noreturn option... " >&6; } + save_CFLAGS="$CFLAGS" + if expr "x-Wmissing-noreturn" : "x-W.*" >/dev/null + then + CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -Wmissing-noreturn" + elif expr "x-Wmissing-noreturn" : "x-f.*" >/dev/null + then + CFLAGS="$CFLAGS -Werror -Wmissing-noreturn" + elif expr "x-Wmissing-noreturn" : "x-m.*" >/dev/null + then + CFLAGS="$CFLAGS -Werror -Wmissing-noreturn" + else + CFLAGS="$CFLAGS -Wmissing-noreturn" + 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 -Wmissing-noreturn" + +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/diag-control.h b/diag-control.h index 6c2d4f45..751faa08 100644 --- a/diag-control.h +++ b/diag-control.h @@ -75,7 +75,8 @@ #define DIAG_OFF_FLEX \ PCAP_DO_PRAGMA(clang diagnostic push) \ PCAP_DO_PRAGMA(clang diagnostic ignored "-Wsign-compare") \ - PCAP_DO_PRAGMA(clang diagnostic ignored "-Wdocumentation") + PCAP_DO_PRAGMA(clang diagnostic ignored "-Wdocumentation") \ + PCAP_DO_PRAGMA(clang diagnostic ignored "-Wmissing-noreturn") #define DIAG_ON_FLEX \ PCAP_DO_PRAGMA(clang diagnostic pop) #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6) diff --git a/gencode.c b/gencode.c index 5846c4f9..642c068a 100644 --- a/gencode.c +++ b/gencode.c @@ -417,7 +417,7 @@ struct _compiler_state { int cur_chunk; }; -void +void PCAP_NORETURN bpf_syntax_error(compiler_state_t *cstate, const char *msg) { bpf_error(cstate, "syntax error in filter expression: %s", msg); @@ -425,7 +425,7 @@ bpf_syntax_error(compiler_state_t *cstate, const char *msg) } /* VARARGS */ -void +void PCAP_NORETURN bpf_error(compiler_state_t *cstate, const char *fmt, ...) { va_list ap; @@ -646,7 +646,7 @@ gen_retblk(compiler_state_t *cstate, int v) return b; } -static inline void +static inline PCAP_NORETURN void syntax(compiler_state_t *cstate) { bpf_error(cstate, "syntax error in filter expression"); diff --git a/gencode.h b/gencode.h index 58828ecd..f1bad215 100644 --- a/gencode.h +++ b/gencode.h @@ -369,7 +369,7 @@ struct icode { }; void bpf_optimize(compiler_state_t *, struct icode *ic); -void bpf_syntax_error(compiler_state_t *, const char *); +void PCAP_NORETURN bpf_syntax_error(compiler_state_t *, const char *); void PCAP_NORETURN bpf_error(compiler_state_t *, const char *, ...) PCAP_PRINTFLIKE(2, 3); diff --git a/grammar.y b/grammar.y index 5aa6f38b..8af53e8a 100644 --- a/grammar.y +++ b/grammar.y @@ -199,7 +199,7 @@ str2tok(const char *str, const struct tok *toks) static struct qual qerr = { Q_UNDEF, Q_UNDEF, Q_UNDEF, Q_UNDEF }; -static void +static PCAP_NORETURN void yyerror(void *yyscanner, compiler_state_t *cstate, const char *msg) { bpf_syntax_error(cstate, msg); diff --git a/rpcapd/rpcapd.c b/rpcapd/rpcapd.c index d3594081..b7e026bc 100755 --- a/rpcapd/rpcapd.c +++ b/rpcapd/rpcapd.c @@ -459,7 +459,7 @@ void main_startup(void) - when we're running in console and are terminated with ^C; - on UN*X, when we're terminated with SIGTERM. */ -static void main_terminate(int sign) +static PCAP_NORETURN void main_terminate(int sign) { SOCK_ASSERT(PROGRAM_NAME " is closing.\n", 1);