diff options
author | Guy Harris <guy@alum.mit.edu> | 2018-06-21 23:11:05 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2018-06-21 23:11:05 -0700 |
commit | be18c1521d1436be38a7024ada3ddef95f412554 (patch) | |
tree | 323ebb6153a791f92e5a6bcd7c679ecf5a39709a /optimize.c | |
parent | 02fcc94b72560e5ccb5800822178c829965a9256 (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.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -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) |