Re: [PATCH] PR libstdc++/81751 don't call fflush(NULL)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

Re: [PATCH] PR libstdc++/81751 don't call fflush(NULL)

Jonathan Wakely-3
On 09/08/17 18:39 +0200, Paolo Carlini wrote:

>> On 9 Aug 2017, at 17:56, Jonathan Wakely <[hidden email]> wrote:
>> This fixes a couple of problems in __gnu_cxx::stdio_filebuf,
>> specifically in the __basic_file::sys_open(FILE*, openmode) function
>> it uses when constructed from an existing FILE stream.
>> Firstly, r86756 changed __basic_file::sys_open(FILE*, openmode) to put
>> the call to sync() before the assignment that sets _M_cfile. This
>> means the fflush(_M_cfile) call has a null argument, and flushes all
>> open streams. I don't think that was intentional, and we only want to
>> flush the FILE we're constructing the streambuf with. (I think this is
>> a regression from 3.4.3, which just flushed the one stream).
>> Secondly, we zero errno so that we can tell if fflush sets it. We need
>> to restore the original value to meet the promise we make at
>> Paolo, does the this->sync() to fflush(__file) change look right?
>Yes, I went through the audit trail of libstdc++/81751 and the change looks good. Certainly we didn't intentionally want the behavior of fflush(0)!

OK, thanks - I've committed the change to trunk now.