diff options
author | Andrei Zeliankou <zelenkov@nginx.com> | 2024-01-31 15:19:13 +0000 |
---|---|---|
committer | andrey-zelenkov <xim.andrew@gmail.com> | 2024-03-11 16:51:35 +0000 |
commit | 8844d33c0aba5b6232366a1fcfbf2f8f866c2f53 (patch) | |
tree | 4bf5545aefd486fcc33fdcf33e124202e14d6dd6 | |
parent | fdc46759eb6fb983b651bcbfccbcd5e6b5658bb6 (diff) | |
download | unit-8844d33c0aba5b6232366a1fcfbf2f8f866c2f53.tar.gz unit-8844d33c0aba5b6232366a1fcfbf2f8f866c2f53.tar.bz2 |
Fixed undefined behaviour in left shift of int value
Found by UndefinedBehaviorSanitizer:
src/nxt_random.c:151:31: runtime error: left shift of 140 by 24 places cannot be represented in type 'int'
#0 0x104f78968 in nxt_random nxt_random.c:151
#1 0x104f58a98 in nxt_shm_open nxt_port_memory.c:377
#2 0x10503e24c in nxt_controller_conf_send nxt_controller.c:617
#3 0x105041154 in nxt_controller_process_request nxt_controller.c:1109
#4 0x104fcdc48 in nxt_event_engine_start nxt_event_engine.c:542
#5 0x104f27254 in main nxt_main.c:35
#6 0x180fbd0dc (<unknown module>)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/nxt_random.c:151:31
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
-rw-r--r-- | src/nxt_random.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/nxt_random.c b/src/nxt_random.c index 1211896c..8290488c 100644 --- a/src/nxt_random.c +++ b/src/nxt_random.c @@ -148,10 +148,10 @@ nxt_random(nxt_random_t *r) nxt_random_stir(r); } - val = nxt_random_byte(r) << 24; - val |= nxt_random_byte(r) << 16; - val |= nxt_random_byte(r) << 8; - val |= nxt_random_byte(r); + val = (uint32_t) nxt_random_byte(r) << 24; + val |= (uint32_t) nxt_random_byte(r) << 16; + val |= (uint32_t) nxt_random_byte(r) << 8; + val |= (uint32_t) nxt_random_byte(r); return val; } |