This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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?

	PR libstdc++/79820
	PR libstdc++/81751
	* config/io/basic_file_stdio.cc (sys_open(FILE*, ios_base::openmode)):
	Call fflush on the stream instead of calling sync() while _M_cfile is
	null. Restore original value of errno.
	* testsuite/ext/stdio_filebuf/char/79820.cc: New.
	* testsuite/ext/stdio_filebuf/char/81751.cc: New.

Tested powerpc64le-linux, not yet committed.

Attachment: patch.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]