]> The Tcpdump Group git mirrors - libpcap/commitdiff
NPF: squelch some warnings about enum values not handled in switches.
authorGuy Harris <[email protected]>
Fri, 3 Jul 2020 22:21:47 +0000 (15:21 -0700)
committerGuy Harris <[email protected]>
Fri, 3 Jul 2020 22:21:47 +0000 (15:21 -0700)
The AppVeyor CI builder started warning about switch statements in which
not all enum values were handled explicitly on the VS 1019 build.  We
can't test for the enum values at compile time, the way we could test
for #defines, so, for now, we punt on the NdisPhysicalMedium enums and
just suppress that diagnostic for that switch statement.

We add MediaConnectStateUnknown to the switch for the connect state;
that one is presumably there if the enum is there at all.

diag-control.h
pcap-npf.c

index 7ea16918f26b9823e6187cf660a7ede08349064d..28ecca42ef60a9dabff2bc164992848d56be3c89 100644 (file)
   #define PCAP_DO_PRAGMA(x) _Pragma (#x)
 #endif
 
+/*
+ * Suppress "enum value not explicitly handled in switch" warnings.
+ * We may have to build on multiple different Windows SDKs, so we
+ * may not be able to include all enum values in a switch, as they
+ * won't necessarily be defined on all the SDKs, and, unlike
+ * #defines, there's no easy way to test whether a given enum has
+ * a given value.  It *could* be done by the configure script or
+ * CMake tests.
+ */
+#if defined(_MSC_VER)
+  #define DIAG_OFF_ENUM_SWITCH \
+    __pragma(warning(push)) \
+    __pragma(warning(disable:4061))
+  #define DIAG_ON_ENUM_SWITCH \
+    __pragma(warning(pop))
+#else
+  #define DIAG_OFF_ENUM_SWITCH
+  #define DIAG_ON_ENUM_SWITCH
+#endif
+
 /*
  * Suppress Flex, narrowing, and deprecation warnings.
  */
index e398d24745c283db76e2bfdbf088d5fa818e3455..4a66fc1f59cf090308e717a188b84c92b111ea14 100644 (file)
@@ -1701,7 +1701,13 @@ get_if_flags(const char *name, bpf_u_int32 *flags, char *errbuf)
        if (status == 0) {
                /*
                 * We got the physical medium.
+                *
+                * XXX - we might want to check for NdisPhysicalMediumWiMax
+                * and NdisPhysicalMediumNative802_15_4 being
+                * part of the enum, and check for those in the "wireless"
+                * case.
                 */
+DIAG_OFF_ENUM_SWITCH
                switch (phys_medium) {
 
                case NdisPhysicalMediumWirelessLan:
@@ -1718,10 +1724,11 @@ get_if_flags(const char *name, bpf_u_int32 *flags, char *errbuf)
 
                default:
                        /*
-                        * Not wireless.
+                        * Not wireless or unknown
                         */
                        break;
                }
+DIAG_ON_ENUM_SWITCH
        }
 #endif
 
@@ -1753,6 +1760,7 @@ get_if_flags(const char *name, bpf_u_int32 *flags, char *errbuf)
                        *flags |= PCAP_IF_CONNECTION_STATUS_DISCONNECTED;
                        break;
 
+               case MediaConnectStateUnknown:
                default:
                        /*
                         * It's unknown whether it's connected or not.