LibC: Return nullptr in fgets for size=0

I had this assert trigger, I believe in a legitimate case.
This is the behavior glic and musl follow.
This commit is contained in:
Yonatan Goldschmidt 2020-05-10 23:34:02 +03:00 committed by Andreas Kling
parent ebe47de0b2
commit 6571468525
Notes: sideshowbarker 2024-07-19 06:44:24 +09:00

View file

@ -137,7 +137,10 @@ int fflush(FILE* stream)
char* fgets(char* buffer, int size, FILE* stream)
{
ASSERT(stream);
ASSERT(size);
if (size == 0) {
return nullptr;
}
ssize_t nread = 0;
while (nread < (size - 1)) {
int ch = fgetc(stream);