9os

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit e00b157a98df92ea8aa8ada11f8ca9e17e399668
parent 23dd177eb3058f03c5e55d3f0ab0c3a82bfefeaf
Author: Dimitris Papastamos <dimitris.papastamos@arm.com>
Date:   Thu,  8 Nov 2018 23:04:25 +0000

[libc] Initialize ch to 0 in fgets()

Change-Id: I7529a938acd9a488f15e630e87e0999d56682f27
Signed-off-by: Dimitris Papastamos <dimitris.papastamos@arm.com>

Diffstat:
Msrc/libc/stdio/fgets.c | 8++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/libc/stdio/fgets.c b/src/libc/stdio/fgets.c @@ -4,11 +4,11 @@ char * fgets(char *s, int n, FILE *fp) { - int ch; - char *t = s; + int ch = 0; + char *t; - while (--n > 0 && (ch = getc(fp)) != EOF) { - if ((*t++ = ch) == '\n') + for (t = s; --n > 0; ++t) { + if ((ch = getc(fp)) == EOF || (*t = ch) == '\n') break; } if (ch == EOF && s == t)