From 1987cc69c8c2f071762da025a84903dcc8197855 Mon Sep 17 00:00:00 2001 From: Ori Bernstein Date: Sat, 11 Jul 2020 13:28:58 -0700 Subject: stdio, ape/stdio: fix order of operations in putc When calling putc, we need to return either EOF or the character returned. To distinguish the two, we need to avoid sign extending 0xff. The code attempted to do this, but the order of operations was wrong, so we ended up masking, setting a character, and then sign extending the character. This fixes things so we mask after assignment. --- sys/include/stdio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sys/include/stdio.h') diff --git a/sys/include/stdio.h b/sys/include/stdio.h index d348f179e..8ed8b43a4 100644 --- a/sys/include/stdio.h +++ b/sys/include/stdio.h @@ -92,7 +92,7 @@ int getchar(void); #define getchar() getc(stdin) char *gets(char *); int putc(int, FILE *); -#define putc(c, f) ((f)->wp>=(f)->rp?_IO_putc(c, f):(*(f)->wp++=(c)&_IO_CHMASK)) +#define putc(c, f) ((f)->wp>=(f)->rp?_IO_putc(c, f):((*(f)->wp++=(c))&_IO_CHMASK)) int _IO_putc(int, FILE *); int putchar(int); #define putchar(c) putc(c, stdout) -- cgit v1.2.3