LibC: Fix getline() forgetting to null-terminate on EOF

This commit is contained in:
Sergey Bugaev 2020-03-26 10:09:31 +03:00 committed by Andreas Kling
parent db4da68618
commit 5ba8247cbb
Notes: sideshowbarker 2024-07-19 08:07:18 +09:00

View file

@ -193,6 +193,7 @@ ssize_t getdelim(char** lineptr, size_t* n, int delim, FILE* stream)
int c = fgetc(stream);
if (c == -1) {
if (feof(stream)) {
*ptr = '\0';
return ptr == *lineptr ? -1 : ptr - *lineptr;
} else {
return -1;