summaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorMura Li <mural@ctli.io>2020-12-01 06:14:55 +0000
committerMura Li <mural@ctli.io>2020-12-01 06:14:55 +0000
commitd4030509dc5ebcfb8e3922ab01bda9ada8cd094d (patch)
tree0c88e511fded467d0cf90a0b578a3023923899d6 /lib/std
parentf3109e1faf8de6f98c308aabba79e8db0c0876dd (diff)
downloadmc-master.tar.gz
bytealloc: fix bucket indexingHEADmaster
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 <mural@ctli.io>
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/bytealloc.myr2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/std/bytealloc.myr b/lib/std/bytealloc.myr
index 4cd2b67..c16761d 100644
--- a/lib/std/bytealloc.myr
+++ b/lib/std/bytealloc.myr
@@ -405,7 +405,7 @@ const bitpos : byte[32] = [
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