From 2d96be0322d71ce62e2f68d038070b10a7c9201b Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Mon, 25 Jul 2016 16:05:27 -0700 Subject: Check for, and squelch, signed vs. unsigned comparison errors. Use -Wsign-compare if the compiler supports it. If we're comparing an unsigned value with a signed value, and we've already determined that the signed value is >= 0, just cast it to an unsigned type. Use 0xffffffffU instead of -1 as the "unknown"/"unset"/etc. value for unsigned variables and fields. Assign the result of str2tok() to an int, not a u_int, as it can return -1. Declare some variables and fields unsigned if they don't need to be signed. Make sure some arguments passed into "set" functions are non-negative (and otherwise not invalid). In the BPF optimizer, cast the "constant" fields of a struct block to an unsigned type - the actual constant field of a BPF instruction is unsigned. Also, cast away one warning from MSVC. --- sf-pcap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sf-pcap.c') diff --git a/sf-pcap.c b/sf-pcap.c index 55c9a579..061964d1 100644 --- a/sf-pcap.c +++ b/sf-pcap.c @@ -876,13 +876,13 @@ pcap_dump_open_append(pcap_t *p, const char *fname) fclose(f); return (NULL); } - if (linktype != ph.linktype) { + if ((bpf_u_int32)linktype != ph.linktype) { pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s: different linktype, cannot append to file", fname); fclose(f); return (NULL); } - if (p->snapshot != ph.snaplen) { + if ((bpf_u_int32)p->snapshot != ph.snaplen) { pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s: different snaplen, cannot append to file", fname); fclose(f); -- cgit v1.2.3