🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Barry Shein Fri, 28 Mar 1986 03:46
Bug in putc
#517
Author: 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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads