diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2014-04-21 18:23:34 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2014-04-21 18:23:34 -0300 |
commit | 2f0a4b3d3a6e6fefd06c7973e54bd7da69dfa0e9 (patch) | |
tree | 1d9f2082fb847d47c8e1c104df5961b5b68bac25 | |
parent | 99bc23771f71d0a1460ff41c2e30f5d4a41963d9 (diff) |
Test realloc failure to make cppcheck happy
-rw-r--r-- | String.c | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -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; |