aboutsummaryrefslogtreecommitdiff
path: root/optimize.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2018-06-21 23:11:05 -0700
committerGuy Harris <guy@alum.mit.edu>2018-06-21 23:11:05 -0700
commitbe18c1521d1436be38a7024ada3ddef95f412554 (patch)
tree323ebb6153a791f92e5a6bcd7c679ecf5a39709a /optimize.c
parent02fcc94b72560e5ccb5800822178c829965a9256 (diff)
Do unsigned shifts.
To quote C99 section 6.5.7 "Bitwise shift operators": The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits are filled with zeros. ... If E1 has a signed type and nonnegative value, and E1 x 2^E2 is representable in the result type, then that is the resulting value; otherwise, the behavior is undefined. In practice, this is harmless, as long as we don't get a trap of some sort in the "isn't representable" case, but we might as well do an unsigned shift - it's just doing hashing, so as long as all the relevant bits get hashed in, that's good enough. This should keep UBSAN quiet.
Diffstat (limited to 'optimize.c')
-rw-r--r--optimize.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/optimize.c b/optimize.c
index 86dcbeef..7c6424b0 100644
--- a/optimize.c
+++ b/optimize.c
@@ -661,7 +661,7 @@ F(opt_state_t *opt_state, int code, int v0, int v1)
int val;
struct valnode *p;
- hash = (u_int)code ^ (v0 << 4) ^ (v1 << 8);
+ hash = (u_int)code ^ ((u_int)v0 << 4) ^ ((u_int)v1 << 8);
hash %= MODULUS;
for (p = opt_state->hashtbl[hash]; p; p = p->next)