LibC: Make getdelim() fail with EINVAL on null input pointers

This matches some other libc's.
This commit is contained in:
Andreas Kling 2020-12-09 21:12:40 +01:00
commit a34e023a33
Notes: sideshowbarker 2024-07-19 00:56:42 +09:00

View file

@ -663,7 +663,11 @@ int getchar()
ssize_t getdelim(char** lineptr, size_t* n, int delim, FILE* stream)
{
char *ptr, *eptr;
if (!lineptr || !n) {
errno = EINVAL;
return -1;
}
if (*lineptr == nullptr || *n == 0) {
*n = BUFSIZ;
if ((*lineptr = static_cast<char*>(malloc(*n))) == nullptr) {
@ -671,6 +675,8 @@ ssize_t getdelim(char** lineptr, size_t* n, int delim, FILE* stream)
}
}
char* ptr;
char* eptr;
for (ptr = *lineptr, eptr = *lineptr + *n;;) {
int c = fgetc(stream);
if (c == -1) {