summaryrefslogtreecommitdiff
path: root/lout/misc.cc
diff options
context:
space:
mode:
authorJorge Arellano Cid <jcid@dillo.org>2016-07-12 14:40:29 -0400
committerJorge Arellano Cid <jcid@dillo.org>2016-07-12 14:40:29 -0400
commit0856f155988da7dfc10eee25157525466ab32f20 (patch)
treec3faec980753c032e10ef8d4d6403239a512f53a /lout/misc.cc
parentf487829c3f7edf56e666d0be79a979b6af46a9bc (diff)
cppcheck: Fix realloc mistake (3 times).
realloc may fail and return NULL, in that case the array contents were lost. Dillo would exit a couple of lines later anyway, but it's better to exit in a clean way.
Diffstat (limited to 'lout/misc.cc')
-rw-r--r--lout/misc.cc7
1 files changed, 5 insertions, 2 deletions
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;
}