public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: libstdc++/5180: seekp() on fstreams opened in read only mode
@ 2002-04-08 23:07 bkoz
  0 siblings, 0 replies; 3+ messages in thread
From: bkoz @ 2002-04-08 23:07 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, kingleo, paolo

Synopsis: seekp() on fstreams opened in read only mode

State-Changed-From-To: feedback->closed
State-Changed-By: bkoz
State-Changed-When: Mon Apr  8 23:07:37 2002
State-Changed-Why:
    The infinte loop is user error, I'm afraid. A better way to write that loop would be:
    
      while (in.good())
        {
          string s;
          getline(in, s);
          cout << s << endl;;
        }
    
    Anyway.
    
    This bug report actually crosses the paths of two library bugs, so this is perhaps why you might see differing interpretations of this code with other compilers and toolchains. 
    
    To wit:
    
      fstream in(name, std::ios::in);
      in.seekp(0); 
      state = in.rdstate();
    
    will give different results. I think state should be failbit, and here's why:
    
        basic_ostream::seekp(pos_type __pos)
        // DR 136
        this->rdbuf()->pubseekpos(__pos, ios_base::out);
        
    then
    
      filebuf::seekpos
      // DR 171
    
    best,
    benjamin

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5180


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: libstdc++/5180: seekp() on fstreams opened in read only mode
@ 2001-12-24  1:45 paolo
  0 siblings, 0 replies; 3+ messages in thread
From: paolo @ 2001-12-24  1:45 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, kingleo, nobody, paolo

Synopsis: seekp() on fstreams opened in read only mode

Responsible-Changed-From-To: unassigned->paolo
Responsible-Changed-By: paolo
Responsible-Changed-When: Mon Dec 24 01:45:56 2001
Responsible-Changed-Why:
    Taking care of it.
State-Changed-From-To: open->feedback
State-Changed-By: paolo
State-Changed-When: Mon Dec 24 01:45:56 2001
State-Changed-Why:
    I think the behaviour you are reporting is standard
    conforming. In fact, after seekp(0) the failbit is set
    and the standard prescribes that all IOStreams operations
    have no effect once the stream state indicates an error
    situation. Compare the behaviour of the testcase with that
    (identical) of:
    
    #include <iostream>
    #include <fstream>
    #include <string>
    
    using namespace std;
    
    int main( int argc, char** argv )
    {
    
      if( argc != 2)
        return 1;
    
      fstream in( argv[1], std::ios::in );
    
      if( !in )
        {
          cout << "cannot open file " << endl;
          return 2;
        }
    
      /*
      in.seekp(0); // <<<<<<<
    
      if (in.rdstate() & ios::failbit)
        {
          cout << "fail" << endl;
          in.clear();
        }
      */
    
      while( !in.eof() )
        {
          string s;
          //getline( in, s );
          cout << s << endl;;
        }
    
      return 0;
    };

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5180


^ permalink raw reply	[flat|nested] 3+ messages in thread

* libstdc++/5180: seekp() on fstreams opened in read only mode
@ 2001-12-23  8:36 kingleo
  0 siblings, 0 replies; 3+ messages in thread
From: kingleo @ 2001-12-23  8:36 UTC (permalink / raw)
  To: gcc-gnats


>Number:         5180
>Category:       libstdc++
>Synopsis:       seekp() on fstreams opened in read only mode
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Dec 23 08:36:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Martin Oberzalek
>Release:        gcc version 3.0.3
>Organization:
>Environment:
debian/linux/unstable on i386; glibc 2.2.4-7
>Description:
if a file is opened via std::fstream in read only mode,
and a seekp(0) will be done std::fstream::eof() will never
return true.
This causes the program to hang in a loop.
>How-To-Repeat:
just compile the program (no Optimation) and start it 
by setting as the first option a simple text file.
$ echo "foobar" > foo && ./test_bug foo
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/x-c++src; name="main.cpp"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="main.cpp"

I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnN0cmVhbT4KI2luY2x1ZGUgPHN0cmluZz4K
CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbiggaW50IGFyZ2MsIGNoYXIqKiBhcmd2ICkK
ewoKICBpZiggYXJnYyAhPSAyKQogICAgcmV0dXJuIDE7CgogIGZzdHJlYW0gaW4oIGFyZ3ZbMV0s
IHN0ZDo6aW9zOjppbiApOwogIAogIGlmKCAhaW4gKQogICAgewogICAgICBjb3V0IDw8ICJjYW5u
b3Qgb3BlbiBmaWxlICIgPDwgZW5kbDsKICAgICAgcmV0dXJuIDI7CiAgICB9CgogIGluLnNlZWtw
KDApOyAvLyA8PDw8PDw8CgogIHdoaWxlKCAhaW4uZW9mKCkgKQogICAgewogICAgICBzdHJpbmcg
czsKICAgICAgZ2V0bGluZSggaW4sIHMgKTsKICAgICAgY291dCA8PCBzIDw8IGVuZGw7OwogICAg
fQogICAgCiAgcmV0dXJuIDA7Cn07Cg==


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-04-09  6:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-08 23:07 libstdc++/5180: seekp() on fstreams opened in read only mode bkoz
  -- strict thread matches above, loose matches on Subject: below --
2001-12-24  1:45 paolo
2001-12-23  8:36 kingleo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).