summaryrefslogtreecommitdiffstats
path: root/String.c
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2014-04-21 18:23:34 -0300
committerHisham Muhammad <hisham@gobolinux.org>2014-04-21 18:23:34 -0300
commit2f0a4b3d3a6e6fefd06c7973e54bd7da69dfa0e9 (patch)
tree1d9f2082fb847d47c8e1c104df5961b5b68bac25 /String.c
parent99bc23771f71d0a1460ff41c2e30f5d4a41963d9 (diff)
Test realloc failure to make cppcheck happy
Diffstat (limited to 'String.c')
-rw-r--r--String.c13
1 files 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;

© 2014-2024 Faster IT GmbH | imprint | privacy policy