cvsuser 04/10/26 08:01:29
Modified: src dod.c
Log:
a << 8 * sizeof(a) is undefined behaviour in C. (ie the answer isn't always 0)
So need to take care of this case explicitly.
Revision Changes Path
1.138 +9 -2 parrot/src/dod.c
Index: dod.c
===================================================================
RCS file: /cvs/public/parrot/src/dod.c,v
retrieving revision 1.137
retrieving revision 1.138
diff -u -r1.137 -r1.138
--- dod.c 22 Oct 2004 13:29:36 -0000 1.137
+++ dod.c 26 Oct 2004 15:01:29 -0000 1.138
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: dod.c,v 1.137 2004/10/22 13:29:36 leo Exp $
+$Id: dod.c,v 1.138 2004/10/26 15:01:29 nicholas Exp $
=head1 NAME
@@ -924,13 +924,20 @@
int i;
int bound = sizeof(size_t) * 8;
- for (i = 0; i <= bound; i++) {
+ /* Shifting a value by its size (in bits) or larger is undefined behaviour.
+ so need an explict check to return 0 if there is no prefix, rather than
+ attempting to rely on (say) 0xFFFFFFFF << 32 being 0 */
+ for (i = 0; i < bound; i++) {
if (val1 == val2) {
return ~(size_t)0 << i;
}
val1 >>= 1;
val2 >>= 1;
}
+ if (val1 == val2) {
+ assert(i == bound);
+ return 0;
+ }
internal_exception(INTERP_ERROR,
"Unexpected condition in find_common_mask()!\n");