diff options
author | Bo Yao <bo@near.org> | 2022-09-29 15:18:08 +0800 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-09-23 13:44:37 +0200 |
commit | 821693c4374d9895f462fa29644905c61dbb241d (patch) | |
tree | 02a0b772374741a184a16972540ad83261bb6535 /lib/quickjs/libbf.c | |
parent | 264bedd6ccc61ed1a87ae599777668937a231f09 (diff) | |
download | chawan-821693c4374d9895f462fa29644905c61dbb241d.tar.gz |
fix undefined behavior: shift 32 bits for uint32_t in bf_set_ui
Diffstat (limited to 'lib/quickjs/libbf.c')
-rw-r--r-- | lib/quickjs/libbf.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/quickjs/libbf.c b/lib/quickjs/libbf.c index fe1628e7..63e7daeb 100644 --- a/lib/quickjs/libbf.c +++ b/lib/quickjs/libbf.c @@ -235,8 +235,13 @@ int bf_set_ui(bf_t *r, uint64_t a) a0 = a; a1 = a >> 32; shift = clz(a1); + // shift < 32 because a > 0xffffffff r->tab[0] = a0 << shift; - r->tab[1] = (a1 << shift) | (a0 >> (LIMB_BITS - shift)); + if (shift == 0) { + r->tab[1] = a1; + } else { + r->tab[1] = (a1 << shift) | (a0 >> (LIMB_BITS - shift)); + } r->expn = 2 * LIMB_BITS - shift; } #endif |