From 2daf48e724d59ff0094a8d7ff9af9936ca5c84ab Mon Sep 17 00:00:00 2001 From: Matt Valentine-House Date: Fri, 13 Feb 2026 13:37:49 +0000 Subject: 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. --- gc/default/default.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); } -- cgit v1.2.3