diff options
| author | Matt Valentine-House <matt@eightbitraptor.com> | 2026-02-13 13:37:49 +0000 |
|---|---|---|
| committer | Matt Valentine-House <matt@eightbitraptor.com> | 2026-02-13 14:29:14 +0000 |
| commit | 2daf48e724d59ff0094a8d7ff9af9936ca5c84ab (patch) | |
| tree | d0bd3cbc9b73050a81ecfb2b4b758de1aecf4e22 | |
| parent | b53aada8da9615b4818da3d87dd92a5f2aea89b8 (diff) | |
Use UINT32_MAX as magic divisor
As @jhawthorn pointed out, the original calculation used `(1 << 32) /
heap->slot_size + 1)` which leads to a subtle off by one error that gets
shifted away because our slot sizes aren't powers of 2.
This is still worth fixing now, so that we don't trip up over it if we
change slot sizes in the future.
| -rw-r--r-- | gc/default/default.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/gc/default/default.c b/gc/default/default.c index 186506c430..9771af004e 100644 --- a/gc/default/default.c +++ b/gc/default/default.c @@ -9511,7 +9511,7 @@ rb_gc_impl_objspace_init(void *objspace_ptr) rb_heap_t *heap = &heaps[i]; heap->slot_size = (1 << i) * BASE_SLOT_SIZE; - slot_div_magics[i] = (uint32_t)(((uint64_t)1 << 32) / heap->slot_size + 1); + slot_div_magics[i] = (uint32_t)((uint64_t)UINT32_MAX / heap->slot_size + 1); ccan_list_head_init(&heap->pages); } |
