std::basic_filebuf<>: sync() after close() calls __rw_fseek() on closed file ----------------------------------------------------------------------------
Key: STDCXX-969 URL: https://issues.apache.org/jira/browse/STDCXX-969 Project: C++ Standard Library Issue Type: Bug Components: 27. Input/Output Affects Versions: 4.2.1, 4.2.0, 4.1.4, 4.1.3, 4.1.2 Environment: All Reporter: Farid Zaripov Fix For: 4.2.2 {code:title=test.cpp} #include <fstream> int main (int argc, char* argv[]) { std::ifstream fs (argv [0], std::ios::binary); char c; fs.get (c); fs.close (); fs.sync (); return 0; } {code} In the test above the fs.sync() calls __rw_fseek(0, ...), that leads to lseek (-1, ...). The proposed patch: {code:title=fstream.cc.diff} Index: include/fstream.cc =================================================================== --- include/fstream.cc (revision 667432) +++ include/fstream.cc (working copy) @@ -106,6 +106,8 @@ _C_file = 0; _C_cur_pos = _C_beg_pos = pos_type (off_type (-1)); + this->setg(0, 0, 0); + this->setp(0, 0); } // rethrow the caught exception @@ -119,6 +121,9 @@ // zero out the file pointer except when detaching fd _C_file = 0; _C_cur_pos = _C_beg_pos = pos_type (off_type (-1)); + + this->setg(0, 0, 0); + this->setp(0, 0); } return __retval; {code} -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.