stdcxx-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin Sebor (JIRA)" <j...@apache.org>
Subject [jira] Commented: (STDCXX-969) std::basic_filebuf<>: sync() after close() calls __rw_fseek() on closed file
Date Wed, 25 Jun 2008 00:21:44 GMT

    [ https://issues.apache.org/jira/browse/STDCXX-969?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12607816#action_12607816
] 

Martin Sebor commented on STDCXX-969:
-------------------------------------

The standard says this in [filebuf]:

{quote}
2  The restrictions on reading and writing a sequence controlled by an object of class {{basic_filebuf<charT,traits>}}
are the same as for reading and writing with the Standard C library {{FILE}}s.
3  In particular:
* If the file is not open for reading the input sequence cannot be read.
* If the file is not open for writing the output sequence cannot be written.
*  A joint file position is maintained for both the input sequence and the output sequence.
{quote}

{{int sync()}}

??Effects:?? If a put area exists, calls {{filebuf::overflow()}} to write the characters to
the file. If a get area exists, the effect is implementation-defined.

Our [documentation|http://stdcxx.apache.org/doc/stdlibref/basic-filebuf.html#idx63] for the
function has this much to say:

{quote}
{{int sync();}}

  Synchronizes the contents of the external file, with its image maintained in memory by the
file buffer. This is useful, for instance, when two threads of execution simultaneously manipulate
the same file. If the function fails, it returns -1; otherwise, it returns 0.
{quote}

> 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.1.2, 4.1.3, 4.1.4, 4.2.0, 4.2.1
>         Environment: All
>            Reporter: Farid Zaripov
>             Fix For: 4.2.2
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> {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.


Mime
View raw message