diff --git a/src/memory.c b/src/memory.c index 88b18ca..46b7b7f 100644 --- a/src/memory.c +++ b/src/memory.c @@ -204,16 +204,11 @@ TR_malloc(size_t size) size = 1 << (MIN_BITS - 1); idx = 0; } else { - size_t mask; - - idx = TR_bitwidth(size); - mask = (1 << (idx + 1)) - 1; + // size-1 to ensure that powers of two will not be + // changed to the next power of two + idx = TR_bitwidth(size-1) + 1; + size = 1 << idx; idx -= (MIN_BITS - 1); - - if (size != (size & ~(mask >> 1))) { - size = (size << 1) & ~mask; - idx++; - } } }