This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/81751] __basic_file::sync() may flush _all_ files
- From: "bugzilla.volker at kabelmail dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 09 Aug 2017 14:27:54 +0000
- Subject: [Bug libstdc++/81751] __basic_file::sync() may flush _all_ files
- Auto-submitted: auto-generated
- References: <bug-81751-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81751
--- Comment #5 from Volker Wehrs <bugzilla.volker at kabelmail dot de> ---
I'm sorry but I ignored the first if-clause in sys_open(). That if-clause makes
sure there is no open file referenced by the __basic_file, otherwise sys_open()
fails.
Then the sync() is called before the new __file is set, so in the current
implementation sync() can only see a _M_cfile set to NULL. Thus sync() is wrong
here.
Note that currently the new file (in __file) is implicitly flushed by the call
to fflush("NULL"), i.e. "flush all". So the new file should be sync'd
explicitly.
So sys_open() might look like this:
__basic_file<char>*
__basic_file<char>::sys_open(__c_file* __file, ios_base::openmode)
{
__basic_file* __ret = NULL;
if (!this->is_open() && __file)
{
_M_cfile = __file;
_M_cfile_created = false;
__ret = this;
this->sync();
}
return __ret;
}
[...]
int
__basic_file<char>::sync()
{
int __err;
do
__err = fflush(_M_cfile);
while ( __err && errno == EINTR );
return __err;
}