realloc(NULL, size) behaves the same as malloc(size) so there is no need
to distinguish between the two.
[kzak@redhat.com: - better handle realloc() errors]
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: Karel Zak <kzak@redhat.com>
if (n == -1 || n < NLOOPS_DEFAULT)
continue;
if (count + 1 > arylen) {
+ int *tmp;
+
arylen += 1;
- *ary = *ary ? realloc(*ary, arylen * sizeof(int)) :
- malloc(arylen * sizeof(int));
- if (!*ary)
+
+ tmp = realloc(*ary, arylen * sizeof(int));
+ if (!tmp) {
+ free(*ary);
return -1;
+ }
+ *ary = tmp;
}
(*ary)[count++] = n;
}