Test realloc failure to make cppcheck happy

This commit is contained in:
Hisham Muhammad 2014-04-21 18:23:34 -03:00
parent 99bc23771f
commit 2f0a4b3d3a
1 changed files with 11 additions and 2 deletions

View File

@ -68,7 +68,13 @@ char** String_split(const char* s, char sep, int* n) {
ctr++; ctr++;
if (ctr == blocks) { if (ctr == blocks) {
blocks += rate; 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; s += size + 1;
} }
@ -79,7 +85,10 @@ char** String_split(const char* s, char sep, int* n) {
out[ctr] = token; out[ctr] = token;
ctr++; ctr++;
} }
out = realloc(out, sizeof(char*) * (ctr + 1)); char** newOut = realloc(out, sizeof(char*) * (ctr + 1));
if (newOut) {
out = newOut;
}
out[ctr] = NULL; out[ctr] = NULL;
*n = ctr; *n = ctr;
return out; return out;