🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.bugs
Article #517

Bug in putc

#517
From: Barry Shein
Date: Fri, 28 Mar 1986 03:46
25 lines
1694 bytes
>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
Technical Details
Message-ID: <320@bu-cs.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!bu-cs!bzs

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site bu-cs.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!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: Sat, 29-Mar-86 05:54:43 EST
Organization: Boston Univ Comp. Sci.
Lines: 25