ref: d4030509dc5ebcfb8e3922ab01bda9ada8cd094d
parent: f3109e1faf8de6f98c308aabba79e8db0c0876dd
author: Mura Li <[email protected]>
date: Tue Dec 1 01:14:55 EST 2020
bytealloc: fix bucket indexing Previously, a blob of size N, where N is a power of 2, will be placed into the 2N-sized bucket. It turns out that the 128 KiB allocation will be assigned to a non-existent 256 KiB bucket and crash the program. Signed-off-by: Mura Li <[email protected]>
--- a/lib/std/bytealloc.myr
+++ b/lib/std/bytealloc.myr
@@ -405,7 +405,7 @@
const bktnum = {sz
var n, v
- v = (sz >> 3 : uint32)
+ v = sz > 0 ? ((sz - 1) >> 3 : uint32) : 0
v |= v >> 1
v |= v >> 2
v |= v >> 4