Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions libs/libc/stdio/lib_getdelim.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,14 @@ ssize_t getdelim(FAR char **lineptr, size_t *n, int delimiter,
goto errout;
}

/* Verify the buffer size */
/* Verify the buffer size. POSIX requires that a NULL *lineptr be
* (re)allocated regardless of the value of *n, so do not trust *n when
* there is no buffer: a caller may legitimately pass *lineptr == NULL with
* an uninitialized *n.
*/

bufsize = *n;
if (bufsize == 0)
if (*lineptr == NULL || bufsize == 0)
{
/* Pick an initial buffer size */

Expand Down
Loading