From 2f0a4b3d3a6e6fefd06c7973e54bd7da69dfa0e9 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 21 Apr 2014 18:23:34 -0300 Subject: Test realloc failure to make cppcheck happy --- String.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/String.c b/String.c index bd458e29..cbfd6877 100644 --- a/String.c +++ b/String.c @@ -68,7 +68,13 @@ char** String_split(const char* s, char sep, int* n) { ctr++; if (ctr == blocks) { blocks += rate; - out = (char**) realloc(out, sizeof(char*) * blocks); + char** newOut = (char**) realloc(out, sizeof(char*) * blocks); + if (newOut) { + out = newOut; + } else { + blocks -= rate; + break; + } } s += size + 1; } @@ -79,7 +85,10 @@ char** String_split(const char* s, char sep, int* n) { out[ctr] = token; ctr++; } - out = realloc(out, sizeof(char*) * (ctr + 1)); + char** newOut = realloc(out, sizeof(char*) * (ctr + 1)); + if (newOut) { + out = newOut; + } out[ctr] = NULL; *n = ctr; return out; -- cgit v1.2.3