summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <mike@xagasoft.com>2013-04-21 21:43:19 -0600
committerMike Buland <mike@xagasoft.com>2013-04-21 21:43:19 -0600
commit7b87784eaf497a976b56be4fd169fb52c9bf7dea (patch)
tree5a6bb44b453e7a28806bf540967592239127a011 /src
parent868af20101c99649b41489e8fcd2e118e20e76ec (diff)
downloadclic-7b87784eaf497a976b56be4fd169fb52c9bf7dea.tar.gz
clic-7b87784eaf497a976b56be4fd169fb52c9bf7dea.tar.bz2
clic-7b87784eaf497a976b56be4fd169fb52c9bf7dea.tar.xz
clic-7b87784eaf497a976b56be4fd169fb52c9bf7dea.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/packedintarray.cpp6
1 files 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()
207 { 207 {
208// Bu::println("!!! Resizing !!!"); 208// Bu::println("!!! Resizing !!!");
209 Store *aOldData = aData; 209 Store *aOldData = aData;
210 int iNewSize = StoreCount(iCapacity*2); 210 int iNewSize = (iCapacity==0)?(bitsizeof(Store)/iBitWidth):(iCapacity=StoreCount(iCapacity*2));
211 while( iNewSize < iCount )
212 iNewSize *= 2;
211 int iSize = StoreCount(iCapacity); 213 int iSize = StoreCount(iCapacity);
212// Bu::println(" %1 => %2 (%3 bit words)").arg( iSize ).arg( iNewSize ) 214// Bu::println(" %1 => %2 (%3 bit words)").arg( iSize ).arg( iNewSize )
213// .arg( StoreBits ); 215// .arg( StoreBits );
214 aData = new Store[iNewSize]; 216 aData = new Store[iNewSize];
215 memset( aData, 0, iNewSize*sizeof(Store) ); 217 memset( aData, 0, iNewSize*sizeof(Store) );
216 memcpy( aData, aOldData, iSize*sizeof(Store) ); 218 memcpy( aData, aOldData, iSize*sizeof(Store) );
217 iCapacity *= 2; 219 iCapacity = (iNewSize*bitsizeof(Store))/iBitWidth;
218 delete[] aOldData; 220 delete[] aOldData;
219 } 221 }
220} 222}