]> The Tcpdump Group git mirrors - libpcap/commitdiff
Squelch a warning in pcap_open_offline_with_tstamp_precision().
authorDenis Ovsienko <[email protected]>
Sun, 1 Aug 2021 22:16:46 +0000 (23:16 +0100)
committerGuy Harris <[email protected]>
Sun, 20 Feb 2022 23:11:54 +0000 (15:11 -0800)
Clang 10.0.1 on NetBSD 9.2 and OpenBSD 6.9:

./savefile.c:354:4: warning: code will never be executed
  [-Wunreachable-code]

In Linux, for example, stdin is a pointer to FILE, so it can be NULL or
non-NULL. In NetBSD and OpenBSD it is a macro:

 #define stdin   (&__sF[0])

By definition, address of a variable is never NULL hence the warning.
However, assigning the address to a pointer and then immediately
comparing the pointer with NULL is not a condition that is always false,
as far as Clang sees it. Apply the workaround and remove two exemption
rules from build.sh.

(cherry picked from commit 57c96726059fa3f05bc1cbeeb2de37497c9ec9ed)

build.sh
savefile.c

index a0321bcbb5c3865bbc6f311cc602dabeab8abe1b..8ea82f5d9f721398d816afa633e4f25d0f306824 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -49,15 +49,6 @@ clang-*/NetBSD-*)
     # 'long' to 'suseconds_t' (aka 'int') [-Wshorten-64-to-32]
     LIBPCAP_TAINTED=yes
     ;;
-clang-*/NetBSD-*)
-    # savefile.c:354:4: warning: code will never be executed
-    # [-Wunreachable-code]
-    LIBPCAP_TAINTED=yes
-    ;;
-clang-*/OpenBSD-*)
-    # Same as the above.
-    LIBPCAP_TAINTED=yes
-    ;;
 esac
 # shellcheck disable=SC2006
 [ "$LIBPCAP_TAINTED" != yes ] && CFLAGS=`cc_werr_cflags`
index d04b917a5b810a28bf2025d639cff1096d68ce10..7543b0fc5658a51d36c8aca82418a0435c64e13d 100644 (file)
@@ -350,7 +350,7 @@ pcap_open_offline_with_tstamp_precision(const char *fname, u_int precision,
        if (fname[0] == '-' && fname[1] == '\0')
        {
                fp = stdin;
-               if (stdin == NULL) {
+               if (fp == NULL) {
                        snprintf(errbuf, PCAP_ERRBUF_SIZE,
                            "The standard input is not open");
                        return (NULL);