From 83e78648e4aa989ce41f6781dafa542d518fe338 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 26 Feb 2019 22:32:51 +0100 Subject: [PATCH] LibC: fgets() should return null on 0-length EOF reads. --- LibC/stdio.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/LibC/stdio.cpp b/LibC/stdio.cpp index baa5dbb53f..33eaff3123 100644 --- a/LibC/stdio.cpp +++ b/LibC/stdio.cpp @@ -104,8 +104,11 @@ char* fgets(char* buffer, int size, FILE* stream) if (nread >= size) break; int ch = fgetc(stream); - if (ch == EOF) + if (ch == EOF) { + if (nread == 0) + return nullptr; break; + } buffer[nread++] = ch; if (!ch || ch == '\n') break;