diff options
author | guy <guy> | 2006-05-28 20:12:28 +0000 |
---|---|---|
committer | guy <guy> | 2006-05-28 20:12:28 +0000 |
commit | d91be5b8afc2d423e1cf2fc71f8c8271a6f8954d (patch) | |
tree | d047c2d6c175144b6b8b02d7db6bd71764d9024c /gencode.c | |
parent | 520a3ea5594674e2b68664a1366aabb25f3c94fe (diff) | |
download | libpcap-d91be5b8afc2d423e1cf2fc71f8c8271a6f8954d.tar.gz |
C89 says that the result of shifting an N-bit value by >= N bits is
undefined; we want it to be zero, so we explicitly check for a 32-bit
shift count and clear the netmask in that case.
Diffstat (limited to 'gencode.c')
-rw-r--r-- | gencode.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -21,7 +21,7 @@ */ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.267 2006-05-18 08:40:52 hannes Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.268 2006-05-28 20:12:28 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -5019,7 +5019,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); |