With a short first line the case can be
*mem = NULL
oldlen = 0
newlen = 5 (anything < 50)
making newbatches == oldbatches == 1 causing the
(newbatches <= oldbatches)
condition to be true.
Let realloc() handle *mem==NULL and use
(!*mem || newbatches > oldbatches) as the only condition.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
int newbatches = (newlen / BATCH_SIZE) + 1;
int oldbatches = (oldlen / BATCH_SIZE) + 1;
- if (newbatches <= oldbatches)
- return;
-
- if (!*mem) {
- do {
- *mem = malloc(newbatches * BATCH_SIZE);
- } while (!*mem);
- } else {
+ if (!*mem || newbatches > oldbatches) {
char *tmp;
do {
tmp = realloc(*mem, newbatches * BATCH_SIZE);