Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!cmcl2!harvard!bu-cs!bzs From: bzs@bu-cs.UUCP (Barry Shein) Newsgroups: net.bugs Subject: Bug in putc Message-ID: <320@bu-cs.UUCP> Date: Thu, 27-Mar-86 22:46:45 EST Article-I.D.: bu-cs.320 Posted: Thu Mar 27 22:46:45 1986 Date-Received: Sun, 20-Apr-86 11:25:28 EST Organization: Boston Univ Comp. Sci. Lines: 25 >There is a bug in the putc macro, in stdio.h. >Putc returns an int which contains the char you have just "put". >However, (at least on both a Pixel and a Sun), the result is sign extended; >if the 8th bit of the char is set, the return value from putc does not equal >the character you put! To fix, replace the putc macro with the following: > >#define putc(x,p) ((int) ((--(p)->_cnt>=0? ((unsigned char)(*(p)->_ptr++=(x))):(unsigned char)_flsbuf((x),p)))) > >Steve Harris WRONG Putc (actually _flsbuf()) can return EOF which on my SUN* is defined as (-1). Doing the above would cause the return value to become 0xff and would not test negative. I believe (uh oh) that what you want here is to change the (unsigned char)s to (unsigned int)s, your timing is off as to when you want it to happen. I tried it on a SUN and it properly returns 0xff for 0xff and -1 for -1. Someone here suggested that it was too bad that EOF was not defined as some negative value like 0xffff0000 (ie. < -255) which is a nice thought but it's too late I suppose, it would have thus been even more out of band (not easily confused with sign-extended 0xff.) -Barry Shein, Boston University