]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Have a #define to squelch -Wunused-result warnings.
authorGuy Harris <[email protected]>
Fri, 1 Dec 2023 09:05:18 +0000 (01:05 -0800)
committerFrancois-Xavier Le Bail <[email protected]>
Sat, 2 Dec 2023 19:17:26 +0000 (20:17 +0100)
In one place, we really *do* legitimately ignore the return value of
pcap_set_datalink(). We cast its return value to void, which appears to
squelch warnings from Clang, but not from at least some versions of GCC,
so provide DIAG_OFF_WARN_UNUSED_RESULT/DIAG_ON_WARN_UNUSED_RESULT and
use them to squelch the warning.

(cherry picked from commit dd821c4f84a9d4956fc39a3a2359cf4ee4652e72)

diag-control.h
tcpdump.c

index 633e4ed0df51dcc9b6d6533004bc20b298e1f2ab..73c745d12c25cfbb8392cce429714e2a07004996 100644 (file)
   #define DIAG_ON_CAST_QUAL \
     DIAG_DO_PRAGMA(GCC diagnostic pop)
 
   #define DIAG_ON_CAST_QUAL \
     DIAG_DO_PRAGMA(GCC diagnostic pop)
 
+  #if ND_IS_AT_LEAST_GNUC_VERSION(4,5)
+    /*
+     * GCC warns about unused return values if a function is marked as
+     * "warn about ignoring this function's return value".
+     *
+     * Clang appears to let you ignore a result without a warning by
+     * casting the function result to void, so we don't appear to
+     * need this for Clang.
+     */
+    #define DIAG_OFF_WARN_UNUSED_RESULT \
+      DIAG_DO_PRAGMA(GCC diagnostic push) \
+      DIAG_DO_PRAGMA(GCC diagnostic ignored "-Wunused-result")
+    #define DIAG_ON_WARN_UNUSED_RESULT \
+      DIAG_DO_PRAGMA(GCC diagnostic pop)
+  #endif
+
   /*
    * Suppress deprecation warnings.
    */
   /*
    * Suppress deprecation warnings.
    */
 #ifndef DIAG_ON_CAST_QUAL
 #define DIAG_ON_CAST_QUAL
 #endif
 #ifndef DIAG_ON_CAST_QUAL
 #define DIAG_ON_CAST_QUAL
 #endif
+#ifndef DIAG_OFF_WARN_UNUSED_RESULT
+#define DIAG_OFF_WARN_UNUSED_RESULT
+#endif
+#ifndef DIAG_ON_WARN_UNUSED_RESULT
+#define DIAG_ON_WARN_UNUSED_RESULT
+#endif
 #ifndef DIAG_OFF_DEPRECATION
 #define DIAG_OFF_DEPRECATION
 #endif
 #ifndef DIAG_OFF_DEPRECATION
 #define DIAG_OFF_DEPRECATION
 #endif
index a6ee95b96f01b5887d56b0d9ea22e947619f01d5..56e9393b83639e016d3498bef0dee9c1bb0bd602 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -2243,8 +2243,11 @@ main(int argc, char **argv)
                         * on; this may be a non-Linux "any" device
                         * that doesn't support DLT_LINUX_SLL2.
                         */
                         * on; this may be a non-Linux "any" device
                         * that doesn't support DLT_LINUX_SLL2.
                         */
-                       if (strcmp(device, "any") == 0)
+                       if (strcmp(device, "any") == 0) {
+DIAG_OFF_WARN_UNUSED_RESULT
                                (void) pcap_set_datalink(pd, DLT_LINUX_SLL2);
                                (void) pcap_set_datalink(pd, DLT_LINUX_SLL2);
+DIAG_ON_WARN_UNUSED_RESULT
+                       }
                }
 #endif
                i = pcap_snapshot(pd);
                }
 #endif
                i = pcap_snapshot(pd);