mirror of
https://github.com/fluencelabs/musl
synced 2025-06-29 06:32:16 +00:00
suppress null termination when fgets reads EOF with no data
the C standard requires that "the contents of the array remain unchanged" in this case. this patch also changes the behavior on read errors, but in that case "the array contents are indeterminate", so the application cannot inspect them anyway.
This commit is contained in:
@ -34,7 +34,7 @@ char *fgets(char *restrict s, int n, FILE *restrict f)
|
|||||||
n--;
|
n--;
|
||||||
if ((*p++ = c) == '\n') break;
|
if ((*p++ = c) == '\n') break;
|
||||||
}
|
}
|
||||||
*p = 0;
|
if (s) *p = 0;
|
||||||
|
|
||||||
FUNLOCK(f);
|
FUNLOCK(f);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user