fix wrong result for putc variants due to operator precedence
authorRich Felker <dalias@aerifal.cx>
Thu, 18 Oct 2018 17:33:11 +0000 (13:33 -0400)
committerRich Felker <dalias@aerifal.cx>
Thu, 18 Oct 2018 17:36:43 +0000 (13:36 -0400)
the internal putc_unlocked macro was wrongly returning a meaningless
boolean result rather than the written character or EOF.

bug was found by reading (very surprising) asm.

src/internal/stdio_impl.h

index ab34da2..4449734 100644 (file)
@@ -105,7 +105,7 @@ hidden void __getopt_msg(const char *, const char *, const char *, size_t);
        ( ((f)->rpos != (f)->rend) ? *(f)->rpos++ : __uflow((f)) )
 
 #define putc_unlocked(c, f) \
-       ( ((unsigned char)(c)!=(f)->lbf && (f)->wpos!=(f)->wend) \
+       ( (((unsigned char)(c)!=(f)->lbf && (f)->wpos!=(f)->wend)) \
        ? *(f)->wpos++ = (c) : __overflow((f),(c)) )
 
 /* Caller-allocated FILE * operations */