Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
4.1.2, 4.1.3, 4.1.4, 4.2.0, 4.2.1
-
None
-
All
-
Patch Available
-
Runtime Error
Description
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; }
In the test above the fs.sync() calls __rw_fseek(0, ...), that leads to lseek (-1, ...).
The proposed patch:
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;