William Corcoran wlc at jctaylor.com
Fri Dec 22 22:42:36 AEST 2017

Brilliant Random832!

Very impressive!

Thank you for the early Christmas present!   Your initial analysis was equally spot on when you interpreted the backtrace.

This is very much appreciated!


Bill Corcoran

On Dec 22, 2017, at 4:09 AM, Random832 <random832 at fastmail.com<mailto:random832 at fastmail.com>> wrote:

On Thu, Dec 21, 2017, at 22:47, William Corcoran wrote:
Could the issue be with fprintf or doprnt.c?

I thought STDERR was unbuffered?   Please forgive me.

I've got it. The problem is with putc (actually _flsbuf), and it is precisely *because* stderr is unbuffered.

#define putc(x, p)    (--(p)->_cnt >= 0 ? \
           ((int) (*(p)->_ptr++ = (unsigned char) (x))) : \
           _flsbuf((unsigned char) (x), (p)))

Under normal circumstances for an unbuffered (or line-buffered) stream, _cnt starts as 0, and therefore every character is passed through _flsbuf.

However, _cnt is still decremented (becoming -1, -2, etc) - _flsbuf should be resetting this to zero (and does in other versions, both earlier and later), but we can see in flsbuf.c it does not. So, after 32769 characters have been output it ticks from -32768 to +32767, and putc now thinks the stream is buffered.

You'll want to add iop->cnt = 0 to the second if clause in _flsbuf.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20171222/f0a7774d/attachment.html>

More information about the TUHS mailing list