From 7b87784eaf497a976b56be4fd169fb52c9bf7dea Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 21 Apr 2013 21:43:19 -0600 Subject: Corrected zero-length PackedIntArray bug. If the array was zero elements long and then append was used it wouldn't allocate memory, but it would try to write to a pointer. --- src/packedintarray.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/packedintarray.cpp b/src/packedintarray.cpp index 5397a73..b91358e 100644 --- a/src/packedintarray.cpp +++ b/src/packedintarray.cpp @@ -207,14 +207,16 @@ void PackedIntArray::checkCapacity() { // Bu::println("!!! Resizing !!!"); Store *aOldData = aData; - int iNewSize = StoreCount(iCapacity*2); + int iNewSize = (iCapacity==0)?(bitsizeof(Store)/iBitWidth):(iCapacity=StoreCount(iCapacity*2)); + while( iNewSize < iCount ) + iNewSize *= 2; int iSize = StoreCount(iCapacity); // Bu::println(" %1 => %2 (%3 bit words)").arg( iSize ).arg( iNewSize ) // .arg( StoreBits ); aData = new Store[iNewSize]; memset( aData, 0, iNewSize*sizeof(Store) ); memcpy( aData, aOldData, iSize*sizeof(Store) ); - iCapacity *= 2; + iCapacity = (iNewSize*bitsizeof(Store))/iBitWidth; delete[] aOldData; } } -- cgit v1.2.3