[PATCH] PR libstdc++/81751 don't call fflush(NULL)
Paolo Carlini
paolo.carlini@oracle.com
Wed Aug 9 16:39:00 GMT 2017
Hi,
> On 9 Aug 2017, at 17:56, Jonathan Wakely <jwakely@redhat.com> 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
> https://gcc.gnu.org/onlinedocs/libstdc++/manual/errno.html
>
> 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)!
Thanks!
Paolo
More information about the Libstdc++
mailing list