瀏覽代碼

fix return value of ungetc when argument is outside unsigned char range

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.
Rich Felker 5 年之前
父節點
當前提交
f6ecd0c296
共有 1 個文件被更改,包括 1 次插入1 次删除
  1. 1 1
      src/stdio/ungetc.c

+ 1 - 1
src/stdio/ungetc.c

@@ -16,5 +16,5 @@ int ungetc(int c, FILE *f)
 	f->flags &= ~F_EOF;
 
 	FUNLOCK(f);
-	return c;
+	return (unsigned char)c;
 }