From 65714685259d1ea4ba9d32bc41aee6fc8c56a645 Mon Sep 17 00:00:00 2001 From: Yonatan Goldschmidt Date: Sun, 10 May 2020 23:34:02 +0300 Subject: [PATCH] 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. --- Libraries/LibC/stdio.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Libraries/LibC/stdio.cpp b/Libraries/LibC/stdio.cpp index 35b2c38b88..543f9ee7af 100644 --- a/Libraries/LibC/stdio.cpp +++ b/Libraries/LibC/stdio.cpp @@ -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);