]> The Tcpdump Group git mirrors - libpcap/commitdiff
C89 says that the result of shifting an N-bit value by >= N bits is
authorguy <guy>
Sun, 28 May 2006 20:13:42 +0000 (20:13 +0000)
committerguy <guy>
Sun, 28 May 2006 20:13:42 +0000 (20:13 +0000)
undefined; we want it to be zero, so we explicitly check for a 32-bit
shift count and clear the netmask in that case.

gencode.c

index d39330c9c78293d42b49b9f51260c8da94e0305f..d1c039dbc351db1c11483f81c65c88ee798b66a3 100644 (file)
--- a/gencode.c
+++ b/gencode.c
@@ -21,7 +21,7 @@
  */
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.221.2.38 2006-02-22 10:39:49 hannes Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.221.2.39 2006-05-28 20:13:42 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -5011,7 +5011,14 @@ gen_mcode(s1, s2, masklen, q)
                /* Convert mask len to mask */
                if (masklen > 32)
                        bpf_error("mask length must be <= 32");
-               m = 0xffffffff << (32 - masklen);
+               if (masklen == 0) {
+                       /*
+                        * X << 32 is not guaranteed by C to be 0; it's
+                        * undefined.
+                        */
+                       m = 0;
+               } else
+                       m = 0xffffffff << (32 - masklen);
                if ((n & ~m) != 0)
                        bpf_error("non-network bits set in \"%s/%d\"",
                            s1, masklen);