mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-04-14 22:51:50 +03:00
Fix integer overflow in test/unit/hash.c
`final[3]` is `uint8_t`. Integer conversion rank of `uint8_t` is lower than integer conversion rank of `int`, so `uint8_t` got promoted to `int`, which is signed integer type. Shift `final[3]` value left on 24, when leftmost bit is set overflows `int` and it is undefined behaviour. Before this change Undefined Behaviour Sanitizer was unhappy about it with the following message. ``` ../test/unit/hash.c:119:25: runtime error: left shift of 176 by 24 places cannot be represented in type 'int' ``` After this commit problem is gone.
This commit is contained in:
parent
17881ebbfd
commit
52fa9577ba
1 changed files with 5 additions and 2 deletions
|
|
@ -115,8 +115,11 @@ hash_variant_verify_key(hash_variant_t variant, uint8_t *key) {
|
|||
} default: not_reached();
|
||||
}
|
||||
|
||||
computed = (final[0] << 0) | (final[1] << 8) | (final[2] << 16) |
|
||||
(final[3] << 24);
|
||||
computed =
|
||||
((uint32_t)final[0] << 0) |
|
||||
((uint32_t)final[1] << 8) |
|
||||
((uint32_t)final[2] << 16) |
|
||||
((uint32_t)final[3] << 24);
|
||||
|
||||
switch (variant) {
|
||||
#ifdef JEMALLOC_BIG_ENDIAN
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue