diff options
-rw-r--r-- | lout/container.cc | 12 | ||||
-rw-r--r-- | lout/misc.cc | 7 |
2 files changed, 14 insertions, 5 deletions
diff --git a/lout/container.cc b/lout/container.cc index 366a58fa..48b353a6 100644 --- a/lout/container.cc +++ b/lout/container.cc @@ -140,7 +140,10 @@ void Vector::put(Object *newElement, int newPos) if (newPos >= numAlloc) { while (newPos >= numAlloc) numAlloc *= 2; - array = (Object**)realloc(array, numAlloc * sizeof(Object*)); + void *vp; + assert((vp = realloc(array, numAlloc * sizeof(Object*)))); + if (!vp) exit(-2); // when NDEBUG is defined + array = (Object**)vp; } // Insert NULL's into possible gap before new position. @@ -171,10 +174,13 @@ void Vector::insert(Object *newElement, int pos) else { numElements++; - // Allocated memory has to be increased. if (numElements >= numAlloc) { + // Allocated memory has to be increased. numAlloc *= 2; - array = (Object**)realloc(array, numAlloc * sizeof(Object*)); + void *vp; + assert((vp = realloc(array, numAlloc * sizeof(Object*)))); + if (!vp) exit(-2); // when NDEBUG is defined + array = (Object**)vp; } for (int i = numElements - 1; i > pos; i--) diff --git a/lout/misc.cc b/lout/misc.cc index 9b333c93..bffc68f7 100644 --- a/lout/misc.cc +++ b/lout/misc.cc @@ -169,8 +169,11 @@ void BitSet::set(int i, bool val) int newNumBytes = numBytes; while (8 * i >= newNumBytes) newNumBytes *= 2; - bits = - (unsigned char*)realloc(bits, newNumBytes * sizeof(unsigned char)); + + void *vp; + assert((vp = realloc(bits, newNumBytes * sizeof(unsigned char)))); + if (!vp) exit(-2); // when NDEBUG is defined + bits = (unsigned char*)vp; memset(bits + numBytes, 0, newNumBytes - numBytes); numBytes = newNumBytes; } |