diff options
Diffstat (limited to 'src/stdio/getdelim.c')
-rw-r--r-- | src/stdio/getdelim.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/stdio/getdelim.c b/src/stdio/getdelim.c index 30774908..813b09fc 100644 --- a/src/stdio/getdelim.c +++ b/src/stdio/getdelim.c @@ -29,15 +29,16 @@ ssize_t getdelim(char **restrict s, size_t *restrict n, int delim, FILE *restric k = z ? z - f->rpos + 1 : f->rend - f->rpos; if (i+k+1 >= *n) { if (k >= SIZE_MAX/2-i) goto oom; - *n = i+k+2; - if (*n < SIZE_MAX/4) *n *= 2; - tmp = realloc(*s, *n); + size_t m = i+k+2; + if (m < SIZE_MAX/4) m *= 2; + tmp = realloc(*s, m); if (!tmp) { - *n = i+k+2; - tmp = realloc(*s, *n); + m = i+k+2; + tmp = realloc(*s, m); if (!tmp) goto oom; } *s = tmp; + *n = m; } memcpy(*s+i, f->rpos, k); f->rpos += k; |