mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 13:57:34 +00:00
LibC: Make getdelim() fail with EINVAL on null input pointers
This matches some other libc's.
This commit is contained in:
parent
2981f10a5e
commit
a34e023a33
1 changed files with 7 additions and 1 deletions
|
@ -663,7 +663,11 @@ int getchar()
|
||||||
|
|
||||||
ssize_t getdelim(char** lineptr, size_t* n, int delim, FILE* stream)
|
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) {
|
if (*lineptr == nullptr || *n == 0) {
|
||||||
*n = BUFSIZ;
|
*n = BUFSIZ;
|
||||||
if ((*lineptr = static_cast<char*>(malloc(*n))) == nullptr) {
|
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;;) {
|
for (ptr = *lineptr, eptr = *lineptr + *n;;) {
|
||||||
int c = fgetc(stream);
|
int c = fgetc(stream);
|
||||||
if (c == -1) {
|
if (c == -1) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue