From 2bbe6144ff4eb6b68b8b06144bca21bffdf1e8b5 Mon Sep 17 00:00:00 2001 From: nemerle Date: Thu, 17 May 2018 00:35:47 +0200 Subject: [PATCH] Fix PoolAllocator::resize for too large p_new_size The code had a subtle signed/unsigned bug - ```cpp if( signed - unsigned < 0) // signed - unsigned is unsigned in c++, so if( unsigned < 0) // and thus the if block will never be executed ``` Thus all the following code would be ran, including unnecessary retries of compacting the pool. --- core/pool_allocator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/pool_allocator.cpp b/core/pool_allocator.cpp index 017586b92ac..89523142126 100644 --- a/core/pool_allocator.cpp +++ b/core/pool_allocator.cpp @@ -359,7 +359,7 @@ Error PoolAllocator::resize(ID p_mem, int p_new_size) { //p_new_size = align(p_new_size) int _free = free_mem; // - static_area_size; - if ((_free + aligned(e->len)) - alloc_size < 0) { + if (uint32_t(_free + aligned(e->len)) < alloc_size) { mt_unlock(); ERR_FAIL_V(ERR_OUT_OF_MEMORY); };