From c6c06a966a1c8d9feecd17692937ae36179cc774 Mon Sep 17 00:00:00 2001 From: clayjohn Date: Thu, 17 Apr 2025 23:35:34 -0700 Subject: [PATCH] Allow chunk validator to wrap around in RID_Alloc so that we do not need to crash once we have made 2^31 allocations --- core/templates/rid_owner.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/templates/rid_owner.h b/core/templates/rid_owner.h index 3ff34c407e..bda5d84670 100644 --- a/core/templates/rid_owner.h +++ b/core/templates/rid_owner.h @@ -164,8 +164,7 @@ class RID_Alloc : public RID_AllocBase { uint32_t free_chunk = free_index / elements_in_chunk; uint32_t free_element = free_index % elements_in_chunk; - uint32_t validator = (uint32_t)(_gen_id() & 0x7FFFFFFF); - CRASH_COND_MSG(validator == 0x7FFFFFFF, "Overflow in RID validator"); + uint32_t validator = 1 + (uint32_t)(_gen_id() % 0x7FFFFFFF); uint64_t id = validator; id <<= 32; id |= free_index; @@ -329,7 +328,7 @@ public: uint32_t validator = uint32_t(id >> 32); - bool owned = (validator != 0x7FFFFFFF) && (chunks[idx_chunk][idx_element].validator & 0x7FFFFFFF) == validator; + bool owned = (chunks[idx_chunk][idx_element].validator & 0x7FFFFFFF) == validator; if constexpr (THREAD_SAFE) { mutex.unlock();