Hi,

we found some discussion about this issue here:

http://www.velocityreviews.com/forums/t283343-shifting-bits-shift-32-bits-on-32-bit-int.html

In post #4 it reads:
The behaviour of shifts defined only if the value of the right operand is less than the number of bits in the left operand. So shifting a 32-bit value by 32 or more is undefined...

further info in #7:

Better yet, read the first part of section 5.8 of the ISO/IEC 14882:2003
standard:

The behavior is undefined if the right operand is negative,
or greater than or equal to the length in bits of the
promoted left operand.

So it seems that my patch is the proper fix in the end after all. Attached as file, since BT distroyed the formatting.

Thanks
Philipp
--- IPv6addr.c_ORIG	2009-02-17 14:28:45.000000000 +0100
+++ IPv6addr.c	2009-02-17 14:29:24.000000000 +0100
@@ -487,7 +487,10 @@
 			n = plen / 32;
 			memset(mask.s6_addr32 + n + 1, 0, (3 - n) * 4);
 			s = 32 - plen % 32;
-			mask.s6_addr32[n] = 0xffffffff << s;
+			if (s == 32) 
+				mask.s6_addr32[n] = 0x0;
+			else
+				mask.s6_addr32[n] = 0xffffffff << s;
 			mask.s6_addr32[n] = htonl(mask.s6_addr32[n]);
 		}
 

Reply via email to