fix return value of ungetc when argument is outside unsigned char range
authorRich Felker <dalias@aerifal.cx>
Sat, 19 Oct 2019 01:11:44 +0000 (21:11 -0400)
committerRich Felker <dalias@aerifal.cx>
Sat, 19 Oct 2019 01:11:44 +0000 (21:11 -0400)
aside from the special value EOF, ungetc is specified to accept and
convert values outside the range of unsigned char. conversion takes
place automatically as part of assignment when storing into the
buffer, but the return value is also required to be the resulting
converted value, and this requirement was not satisfied.

simplified from patch by Wang Jianjian.

src/stdio/ungetc.c

index 180673a..bc629d4 100644 (file)
@@ -16,5 +16,5 @@ int ungetc(int c, FILE *f)
        f->flags &= ~F_EOF;
 
        FUNLOCK(f);
-       return c;
+       return (unsigned char)c;
 }