Convert codebase to use emalloc.c utility-functions
This also definitely increases readability and makes OOM-conditions more consistent.
This commit is contained in:
@@ -18,7 +18,5 @@ apathmax(char **p, long *size)
|
||||
eprintf("pathconf:");
|
||||
}
|
||||
}
|
||||
|
||||
if (!(*p = malloc(*size)))
|
||||
eprintf("malloc:");
|
||||
*p = emalloc(*size);
|
||||
}
|
||||
|
@@ -16,14 +16,11 @@ getlines(FILE *fp, struct linebuf *b)
|
||||
while ((len = agetline(&line, &size, fp)) != -1) {
|
||||
if (++b->nlines > b->capacity) {
|
||||
b->capacity += 512;
|
||||
nline = realloc(b->lines, b->capacity * sizeof(*b->lines));
|
||||
if (!nline)
|
||||
eprintf("realloc:");
|
||||
nline = erealloc(b->lines, b->capacity * sizeof(*b->lines));
|
||||
b->lines = nline;
|
||||
}
|
||||
linelen = len + 1;
|
||||
if (!(b->lines[b->nlines-1] = malloc(linelen)))
|
||||
eprintf("malloc:");
|
||||
b->lines[b->nlines-1] = emalloc(linelen);
|
||||
memcpy(b->lines[b->nlines-1], line, linelen);
|
||||
}
|
||||
free(line);
|
||||
|
Reference in New Issue
Block a user