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
Родитель 3deb56f719
Коммит 872517ddbb
1 изменённых файлов: 2 добавлений и 2 удалений

Просмотреть файл

@ -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;;) {