diff options
author | Ori Bernstein <ori@eigenstate.org> | 2020-07-11 13:28:58 -0700 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2020-07-11 13:28:58 -0700 |
commit | 1987cc69c8c2f071762da025a84903dcc8197855 (patch) | |
tree | a907daac5c257059a7eacaecf8b918391aa318a5 | |
parent | ad26dc48a6dc05da02f96e5f1e7b82de58ff5b2c (diff) | |
download | plan9front-1987cc69c8c2f071762da025a84903dcc8197855.tar.xz |
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.
-rw-r--r-- | sys/include/ape/stdio.h | 2 | ||||
-rw-r--r-- | sys/include/stdio.h | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/sys/include/ape/stdio.h b/sys/include/ape/stdio.h index 80374c3b6..b05f41e69 100644 --- a/sys/include/ape/stdio.h +++ b/sys/include/ape/stdio.h @@ -106,7 +106,7 @@ extern int getchar(void); #define getchar() getc(stdin) extern char *gets(char *); extern 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)) extern int _IO_putc(int, FILE *); extern int putchar(int); #define putchar(c) putc(c, stdout) 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) |