fflush(NULL) clobbers input streams

Ken Brown kbrown@cornell.edu
Wed Jul 19 02:16:00 GMT 2017


On 7/18/2017 6:41 PM, Ken Brown wrote:
> On 7/18/2017 3:21 PM, Achim Gratz wrote:
>> Corinna Vinschen writes:
>>> Oh, and a plain C testcase, of course...
>>
>> Call that fflush.c:
>>
>> --8<---------------cut here---------------start------------->8---
>> #include <stdio.h>
>> int
>> main(int argc, char **argv)
>> {
>>      char buf[1024];
>>      int i;
>>      char *bp = buf;
>>      while (1) {
>>          while ((i = getc(stdin)) != -1
>>                 && (*bp++ = i) != '\n'
>>                 && bp < &buf[1024])
>>          /* DO NOTHING */ ;
>>          *bp = '\0';
>>          fprintf(stdout, "%s", buf);
>>          fflush(NULL);
>>          if (i == -1)
>>              return 0;
>>          bp = buf;
>>      }
>> }
>> --8<---------------cut here---------------end--------------->8---
>>
>> Then run:
>>
>> gcc fflush.c -o fflush
>> cat fflush.c | ./fflush 2>/dev/null > fflush.out
>> diff fflush.c fflush.out
>>
>> If things are working, fflush.c and fflush.out should be identical.
>> Currently only the first line makes it into fflush.out on Cygwin.
> 
> I've checked that the 2017-03-08 snapshot is good and the 2017-03-10 
> snapshot is bad.  I'll bisect further when I get a chance

Done:

44b1746a41921533d27aca414a9188314cb725b6 is the first bad commit
commit 44b1746a41921533d27aca414a9188314cb725b6
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Fri Mar 10 20:21:09 2017 +0100

     errno: Stop using _impure_ptr->_errno completely

     We use errno AKA _REENT->_errno since the last century and only set
     _impure_ptr->_errno for backward compat.  Stop that.  Also, remove
     the last check for _impure_ptr->_errno in Cygwin code.

Ken



More information about the Cygwin-apps mailing list