summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/getdelim.c
diff options
context:
space:
mode:
authordas <das@FreeBSD.org>2009-10-04 19:43:36 +0000
committerdas <das@FreeBSD.org>2009-10-04 19:43:36 +0000
commitbeb0df0cdc08eb2f41c970801e05caae7e59c786 (patch)
treee0191effc355243819b234f6a389b1647daf95a9 /lib/libc/stdio/getdelim.c
parentdce82c729ad5fad175b28be442aaeb21238ab652 (diff)
downloadFreeBSD-src-beb0df0cdc08eb2f41c970801e05caae7e59c786.zip
FreeBSD-src-beb0df0cdc08eb2f41c970801e05caae7e59c786.tar.gz
Better glibc compatibility for getline/getdelim:
- Tolerate applications that pass a NULL pointer for the buffer and claim that the capacity of the buffer is nonzero. - If an application passes in a non-NULL buffer pointer and claims the buffer has zero capacity, we should free (well, realloc) it anyway. It could have been obtained from malloc(0), so failing to free it would be a small memory leak. MFC After: 2 weeks Reported by: naddy PR: ports/138320
Diffstat (limited to 'lib/libc/stdio/getdelim.c')
-rw-r--r--lib/libc/stdio/getdelim.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/libc/stdio/getdelim.c b/lib/libc/stdio/getdelim.c
index 7af154f..d7d5627 100644
--- a/lib/libc/stdio/getdelim.c
+++ b/lib/libc/stdio/getdelim.c
@@ -120,8 +120,8 @@ getdelim(char ** __restrict linep, size_t * __restrict linecapp, int delim,
goto error;
}
- if (*linecapp == 0)
- *linep = NULL;
+ if (*linep == NULL)
+ *linecapp = 0;
if (fp->_r <= 0 && __srefill(fp)) {
/* If fp is at EOF already, we just need space for the NUL. */
OpenPOWER on IntegriCloud