Skip to content

Commit 2daf48e

Browse files
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.
1 parent b53aada commit 2daf48e

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

gc/default/default.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9511,7 +9511,7 @@ rb_gc_impl_objspace_init(void *objspace_ptr)
95119511
rb_heap_t *heap = &heaps[i];
95129512

95139513
heap->slot_size = (1 << i) * BASE_SLOT_SIZE;
9514-
slot_div_magics[i] = (uint32_t)(((uint64_t)1 << 32) / heap->slot_size + 1);
9514+
slot_div_magics[i] = (uint32_t)((uint64_t)UINT32_MAX / heap->slot_size + 1);
95159515

95169516
ccan_list_head_init(&heap->pages);
95179517
}

0 commit comments

Comments
 (0)