Uploaded image for project: 'C++ Standard Library'
  1. C++ Standard Library
  2. STDCXX-969

std::basic_filebuf<>: sync() after close() calls __rw_fseek() on closed file

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.1.2, 4.1.3, 4.1.4, 4.2.0, 4.2.1
    • 4.2.2
    • 27. Input/Output
    • 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;
      

      Attachments

        Activity

          People

            farid Farid Zaripov
            farid Farid Zaripov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1h
                1h