summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYonatan Goldschmidt <yon.goldschmidt@gmail.com>2020-05-10 23:34:02 +0300
committerAndreas Kling <kling@serenityos.org>2020-05-11 09:50:42 +0200
commit65714685259d1ea4ba9d32bc41aee6fc8c56a645 (patch)
tree56fd758605666253f85105d5ed7cf24374935ebb
parentebe47de0b2e0f35397cf137ae565b8042d81ccd2 (diff)
downloadserenity-65714685259d1ea4ba9d32bc41aee6fc8c56a645.zip
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.
-rw-r--r--Libraries/LibC/stdio.cpp5
1 files changed, 4 insertions, 1 deletions
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);