Defer setting bufsiz in getdelim.

Do not write to bufsiz until we are sure the malloc has succeeded,
in case any callers rely on it (which they shouldn't).  ok djm@
This commit is contained in:
Darren Tucker 2018-07-06 13:32:02 +10:00
parent 3deb56f719
commit 872517ddbb
1 changed files with 2 additions and 2 deletions

View File

@ -53,9 +53,9 @@ getdelim(char **buf, size_t *bufsiz, int delimiter, FILE *fp)
if (*buf == NULL || *bufsiz == 0) {
*bufsiz = BUFSIZ;
if ((*buf = malloc(*bufsiz)) == NULL)
if ((*buf = malloc(BUFSIZ)) == NULL)
return -1;
*bufsiz = BUFSIZ;
}
for (ptr = *buf, eptr = *buf + *bufsiz;;) {