These patches turn on some more warnings (or not) and fixes all warnings that 
come up

Notes:
- 0001 is not sent (it's the previously sent -Wshadow fix)
- 0005 Fixes most of the trivial cases of -Wunused-parameter warnings. It does 
not enable the warning.

Please apply in case they make sense.

Kind regards
   Jörg
-- 
Joerg Mayer                                           <jma...@loplof.de>
We are stuck with technology when what we really want is just stuff that
works. Some say that should read Microsoft instead of technology.
>From a7d8a6af79cc8f4fad3851250e8cff70aea7ee06 Mon Sep 17 00:00:00 2001
From: Joerg Mayer <jma...@loplof.de>
Date: Wed, 28 Mar 2018 09:57:32 +0200
Subject: [PATCH 2/5] Add -Wcomma and fix the single place it complains about

Signed-off-by: Joerg Mayer <jma...@loplof.de>
---
 CMakeLists.txt | 1 +
 gencode.c      | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 05ecb4d5..ba2244ec 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1670,6 +1670,7 @@ if(EXISTS ${CMAKE_SOURCE_DIR}/.devel OR EXISTS 
${CMAKE_BINARY_DIR}/.devel)
         check_and_add_compiler_option(-Wdeclaration-after-statement)
         check_and_add_compiler_option(-Wused-but-marked-unused)
         check_and_add_compiler_option(-Wdocumentation)
+        check_and_add_compiler_option(-Wcomma)
     endif()
 endif()
 
diff --git a/gencode.c b/gencode.c
index 5d0f95a2..5846c4f9 100644
--- a/gencode.c
+++ b/gencode.c
@@ -574,7 +574,8 @@ newchunk(compiler_state_t *cstate, size_t n)
 
        cp = &cstate->chunks[cstate->cur_chunk];
        if (n > cp->n_left) {
-               ++cp, k = ++cstate->cur_chunk;
+               ++cp;
+               k = ++cstate->cur_chunk;
                if (k >= NCHUNKS)
                        bpf_error(cstate, "out of memory");
                size = CHUNK0SIZE << k;
-- 
2.14.3 (Apple Git-98)

>From 9886843362fb8b1685256f76ff1adba9606162f6 Mon Sep 17 00:00:00 2001
From: Joerg Mayer <jma...@loplof.de>
Date: Wed, 28 Mar 2018 11:24:05 +0200
Subject: [PATCH 3/5] 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 <jma...@loplof.de>
---
 CMakeLists.txt  | 1 +
 diag-control.h  | 3 ++-
 gencode.c       | 6 +++---
 gencode.h       | 2 +-
 grammar.y       | 2 +-
 rpcapd/rpcapd.c | 2 +-
 6 files changed, 9 insertions(+), 7 deletions(-)

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/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 53554250..ef10a2d5 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);
 
-- 
2.14.3 (Apple Git-98)

>From 2440973362720e64f5423a610ffce68cb80a3483 Mon Sep 17 00:00:00 2001
From: Joerg Mayer <jma...@loplof.de>
Date: Wed, 28 Mar 2018 11:48:01 +0200
Subject: [PATCH 4/5] Do NOT add -Wcovered-switch-default by default as the
 warnings are genuine but intended

Make the rpcapd/log-stderr.c error case identical to the gencode.c case.

Signed-off-by: Joerg Mayer <jma...@loplof.de>
---
 CMakeLists.txt      | 2 ++
 rpcapd/log-stderr.c | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 16211ac4..cdfaa4bf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1672,6 +1672,8 @@ if(EXISTS ${CMAKE_SOURCE_DIR}/.devel OR EXISTS 
${CMAKE_BINARY_DIR}/.devel)
         check_and_add_compiler_option(-Wdocumentation)
         check_and_add_compiler_option(-Wcomma)
         check_and_add_compiler_option(-Wmissing-noreturn)
+        # Warns about safeguards added in case the enums are extended
+        # check_and_add_compiler_option(-Wcovered-switch-default)
     endif()
 endif()
 
diff --git a/rpcapd/log-stderr.c b/rpcapd/log-stderr.c
index d5054b3b..4fce0ece 100644
--- a/rpcapd/log-stderr.c
+++ b/rpcapd/log-stderr.c
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <stdarg.h>
+#include <stdlib.h>
 #include "log.h"
 
 void
@@ -28,7 +29,7 @@ rpcapd_log(log_priority priority, const char *message, ...)
                break;
 
        default:
-               /* Don't do this. */
+               abort();
                return;
        }
 
-- 
2.14.3 (Apple Git-98)

>From 3a25d7a68f1fe302572e8fe0f3daaf2dc8bcece6 Mon Sep 17 00:00:00 2001
From: Joerg Mayer <jma...@loplof.de>
Date: Wed, 28 Mar 2018 17:20:52 +0200
Subject: [PATCH 5/5] Fix the -Wunused-parameter warnings that have obvious
 fixes

Signed-off-by: Joerg Mayer <jma...@loplof.de>
---
 gencode.c    | 12 ++++++------
 grammar.y    |  6 +++---
 nametoaddr.c |  4 +++-
 optimize.c   | 14 +++++++-------
 pcap.c       |  4 +++-
 savefile.c   |  8 ++++----
 sockutils.c  |  8 ++++++--
 7 files changed, 32 insertions(+), 24 deletions(-)

diff --git a/gencode.c b/gencode.c
index 642c068a..3c2a35d4 100644
--- a/gencode.c
+++ b/gencode.c
@@ -7940,42 +7940,42 @@ gen_pf_action(compiler_state_t *cstate, int action)
 }
 #else /* !HAVE_NET_PFVAR_H */
 struct block *
-gen_pf_ifname(compiler_state_t *cstate, const char *ifname)
+gen_pf_ifname(compiler_state_t *cstate, const char *ifname _U_)
 {
        bpf_error(cstate, "libpcap was compiled without pf support");
        /* NOTREACHED */
 }
 
 struct block *
-gen_pf_ruleset(compiler_state_t *cstate, char *ruleset)
+gen_pf_ruleset(compiler_state_t *cstate, char *ruleset _U_)
 {
        bpf_error(cstate, "libpcap was compiled on a machine without pf 
support");
        /* NOTREACHED */
 }
 
 struct block *
-gen_pf_rnr(compiler_state_t *cstate, int rnr)
+gen_pf_rnr(compiler_state_t *cstate, int rnr _U_)
 {
        bpf_error(cstate, "libpcap was compiled on a machine without pf 
support");
        /* NOTREACHED */
 }
 
 struct block *
-gen_pf_srnr(compiler_state_t *cstate, int srnr)
+gen_pf_srnr(compiler_state_t *cstate, int srnr _U_)
 {
        bpf_error(cstate, "libpcap was compiled on a machine without pf 
support");
        /* NOTREACHED */
 }
 
 struct block *
-gen_pf_reason(compiler_state_t *cstate, int reason)
+gen_pf_reason(compiler_state_t *cstate, int reason _U_)
 {
        bpf_error(cstate, "libpcap was compiled on a machine without pf 
support");
        /* NOTREACHED */
 }
 
 struct block *
-gen_pf_action(compiler_state_t *cstate, int action)
+gen_pf_action(compiler_state_t *cstate, int action _U_)
 {
        bpf_error(cstate, "libpcap was compiled on a machine without pf 
support");
        /* NOTREACHED */
diff --git a/grammar.y b/grammar.y
index 8af53e8a..907b81cb 100644
--- a/grammar.y
+++ b/grammar.y
@@ -200,7 +200,7 @@ str2tok(const char *str, const struct tok *toks)
 static struct qual qerr = { Q_UNDEF, Q_UNDEF, Q_UNDEF, Q_UNDEF };
 
 static PCAP_NORETURN void
-yyerror(void *yyscanner, compiler_state_t *cstate, const char *msg)
+yyerror(void *yyscanner _U_, compiler_state_t *cstate, const char *msg)
 {
        bpf_syntax_error(cstate, msg);
        /* NOTREACHED */
@@ -247,14 +247,14 @@ pfaction_to_num(compiler_state_t *cstate, const char 
*action)
 }
 #else /* !HAVE_NET_PFVAR_H */
 static int
-pfreason_to_num(compiler_state_t *cstate, const char *reason)
+pfreason_to_num(compiler_state_t *cstate, const char *reason _U_)
 {
        bpf_error(cstate, "libpcap was compiled on a machine without pf 
support");
        /*NOTREACHED*/
 }
 
 static int
-pfaction_to_num(compiler_state_t *cstate, const char *action)
+pfaction_to_num(compiler_state_t *cstate, const char *action _U_)
 {
        bpf_error(cstate, "libpcap was compiled on a machine without pf 
support");
        /*NOTREACHED*/
diff --git a/nametoaddr.c b/nametoaddr.c
index 7fca5d46..2b7475ad 100644
--- a/nametoaddr.c
+++ b/nametoaddr.c
@@ -758,9 +758,9 @@ pcap_ether_hostton(const char *name)
  * XXX - not guaranteed to be thread-safe!
  */
 int
+#ifdef DECNETLIB
 __pcap_nametodnaddr(const char *name, u_short *res)
 {
-#ifdef DECNETLIB
        struct nodeent *getnodebyname();
        struct nodeent *nep;
 
@@ -771,6 +771,8 @@ __pcap_nametodnaddr(const char *name, u_short *res)
        memcpy((char *)res, (char *)nep->n_addr, sizeof(unsigned short));
        return(1);
 #else
+__pcap_nametodnaddr(const char *name _U_, u_short *res _U_)
+{
        return(0);
 #endif
 }
diff --git a/optimize.c b/optimize.c
index 0ca639cc..13dd207a 100644
--- a/optimize.c
+++ b/optimize.c
@@ -649,7 +649,7 @@ vstore(struct stmt *s, int *valp, int newval, int alter)
  * (Unary operators are handled elsewhere.)
  */
 static void
-fold_op(compiler_state_t *cstate, struct icode *ic, opt_state_t *opt_state,
+fold_op(compiler_state_t *cstate, opt_state_t *opt_state,
     struct stmt *s, int v0, int v1)
 {
        bpf_u_int32 a, b;
@@ -991,7 +991,7 @@ opt_peep(opt_state_t *opt_state, struct block *b)
  * evaluation and code transformations weren't folded together.
  */
 static void
-opt_stmt(compiler_state_t *cstate, struct icode *ic, opt_state_t *opt_state,
+opt_stmt(compiler_state_t *cstate, opt_state_t *opt_state,
     struct stmt *s, int val[], int alter)
 {
        int op;
@@ -1080,7 +1080,7 @@ opt_stmt(compiler_state_t *cstate, struct icode *ic, 
opt_state_t *opt_state,
                                }
                        }
                        if (opt_state->vmap[val[A_ATOM]].is_const) {
-                               fold_op(cstate, ic, opt_state, s, val[A_ATOM], 
K(s->k));
+                               fold_op(cstate, opt_state, s, val[A_ATOM], 
K(s->k));
                                val[A_ATOM] = K(s->k);
                                break;
                        }
@@ -1101,7 +1101,7 @@ opt_stmt(compiler_state_t *cstate, struct icode *ic, 
opt_state_t *opt_state,
                op = BPF_OP(s->code);
                if (alter && opt_state->vmap[val[X_ATOM]].is_const) {
                        if (opt_state->vmap[val[A_ATOM]].is_const) {
-                               fold_op(cstate, ic, opt_state, s, val[A_ATOM], 
val[X_ATOM]);
+                               fold_op(cstate, opt_state, s, val[A_ATOM], 
val[X_ATOM]);
                                val[A_ATOM] = K(s->k);
                        }
                        else {
@@ -1225,7 +1225,7 @@ opt_deadstores(opt_state_t *opt_state, register struct 
block *b)
 }
 
 static void
-opt_blk(compiler_state_t *cstate, struct icode *ic, opt_state_t *opt_state,
+opt_blk(compiler_state_t *cstate, opt_state_t *opt_state,
     struct block *b, int do_stmts)
 {
        struct slist *s;
@@ -1276,7 +1276,7 @@ opt_blk(compiler_state_t *cstate, struct icode *ic, 
opt_state_t *opt_state,
        aval = b->val[A_ATOM];
        xval = b->val[X_ATOM];
        for (s = b->stmts; s; s = s->next)
-               opt_stmt(cstate, ic, opt_state, &s->s, b->val, do_stmts);
+               opt_stmt(cstate, opt_state, &s->s, b->val, do_stmts);
 
        /*
         * This is a special case: if we don't use anything from this
@@ -1649,7 +1649,7 @@ opt_blks(compiler_state_t *cstate, opt_state_t 
*opt_state, struct icode *ic,
        find_inedges(opt_state, ic->root);
        for (i = maxlevel; i >= 0; --i)
                for (p = opt_state->levels[i]; p; p = p->link)
-                       opt_blk(cstate, ic, opt_state, p, do_stmts);
+                       opt_blk(cstate, opt_state, p, do_stmts);
 
        if (do_stmts)
                /*
diff --git a/pcap.c b/pcap.c
index 64686d32..358c01eb 100644
--- a/pcap.c
+++ b/pcap.c
@@ -616,9 +616,9 @@ get_figure_of_merit(pcap_if_t *dev)
  * description?
  */
 static char *
+#ifdef SIOCGIFDESCR
 get_if_description(const char *name)
 {
-#ifdef SIOCGIFDESCR
        char *description = NULL;
        int s;
        struct ifreq ifrdesc;
@@ -735,6 +735,8 @@ get_if_description(const char *name)
 #endif
        return (description);
 #else /* SIOCGIFDESCR */
+get_if_description(const char *name _U_)
+{
        return (NULL);
 #endif /* SIOCGIFDESCR */
 }
diff --git a/savefile.c b/savefile.c
index 57375224..ec44ef4f 100644
--- a/savefile.c
+++ b/savefile.c
@@ -84,7 +84,7 @@ static pcap_t *pcap_fopen_offline(FILE *, char *);
 #endif
 
 static int
-sf_getnonblock(pcap_t *p)
+sf_getnonblock(pcap_t *p _U_)
 {
        /*
         * This is a savefile, not a live capture file, so never say
@@ -94,7 +94,7 @@ sf_getnonblock(pcap_t *p)
 }
 
 static int
-sf_setnonblock(pcap_t *p, int nonblock)
+sf_setnonblock(pcap_t *p, int nonblock _U_)
 {
        /*
         * This is a savefile, not a live capture file, so reject
@@ -110,7 +110,7 @@ sf_setnonblock(pcap_t *p, int nonblock)
 }
 
 static int
-sf_stats(pcap_t *p, struct pcap_stat *ps)
+sf_stats(pcap_t *p, struct pcap_stat *ps _U_)
 {
        pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
            "Statistics aren't available from savefiles");
@@ -228,7 +228,7 @@ sf_inject(pcap_t *p, const void *buf _U_, size_t size _U_)
  * single device? IN, OUT or both?
  */
 static int
-sf_setdirection(pcap_t *p, pcap_direction_t d)
+sf_setdirection(pcap_t *p, pcap_direction_t d _U_)
 {
        pcap_snprintf(p->errbuf, sizeof(p->errbuf),
            "Setting direction is not supported on savefiles");
diff --git a/sockutils.c b/sockutils.c
index 81be8622..ecd67203 100644
--- a/sockutils.c
+++ b/sockutils.c
@@ -62,6 +62,8 @@
 #define INT_MAX                2147483647
 #endif
 
+#include "pcap-int.h"
+
 #include "sockutils.h"
 #include "portability.h"
 
@@ -218,9 +220,9 @@ void sock_geterror(const char *caller, char *errbuf, int 
errbuflen)
  * \return '0' if everything is fine, '-1' if some errors occurred. The error 
message is returned
  * in the 'errbuf' variable.
  */
+#ifdef _WIN32
 int sock_init(char *errbuf, int errbuflen)
 {
-#ifdef _WIN32
        if (sockcount == 0)
        {
                WSADATA wsaData;                        /* helper variable 
needed to initialize Winsock */
@@ -238,8 +240,10 @@ int sock_init(char *errbuf, int errbuflen)
        }
 
        sockcount++;
+#else
+int sock_init(char *errbuf _U_, int errbuflen _U_)
+{
 #endif
-
        return 0;
 }
 
-- 
2.14.3 (Apple Git-98)

_______________________________________________
tcpdump-workers mailing list
tcpdump-workers@lists.tcpdump.org
https://lists.sandelman.ca/mailman/listinfo/tcpdump-workers

Reply via email to