Bug 2259 - istream::tellg/seekg cause character loss
Summary: istream::tellg/seekg cause character loss
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Benjamin Kosnik
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-03-10 20:36 UTC by hhuang
Modified: 2003-07-25 17:33 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description hhuang 2001-03-10 20:36:00 UTC
istream::tellg causes character loss while using getline(string &).  istream::seekg with the saved value will result in one character beyond the saved position.

Release:
unknown

Environment:
~>gcc -v
Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/2.95.2-6/specs
gcc version 2.95.2-6 19991024 (cygwin experimental)

How-To-Repeat:
This can be demostrated with the attach code and a file with the following 2 lines (the content seem to have an impact on the result):

line1	aaaaaaaa	bbbbbbbb	ccccccccc
line2	dddddddd

The running result is as follows:

0: line1        aaaaaaaa        bbbbbbbb        ccccccccc
gcount = 0
remember 36
0: [ine2        dddddddd]
restore 37
1: [ne2 dddddddd]
Comment 1 hhuang 2001-03-10 20:36:00 UTC
Fix:
No idea yet.
Comment 2 Benjamin Kosnik 2001-03-12 10:39:29 UTC
From: benjamin kosnik <bkoz@nabi.net>
To: gcc-gnats@gcc.gnu.org, nobody@gcc.gnu.org, hhuang@cs.columbia.edu
Cc:  
Subject: Re: libstdc++/2259
Date: Mon, 12 Mar 2001 10:39:29 -0800

 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=2259&database=gcc
 
 
 there is no attached file, so I can't reproduce your problem. Can you
 try this with mainline CVS or the snapshots available on-line at
 codesourcery.com?
 
 thanks,
 benjamin

Comment 3 Benjamin Kosnik 2001-03-12 18:47:11 UTC
From: benjamin kosnik <bkoz@nabi.net>
To: Hao Huang <hhuang@cs.columbia.edu>
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: libstdc++/2259
Date: Mon, 12 Mar 2001 18:47:11 -0800

 > I just downloaded the latest cygwin gcc and the bug seems to be fixed.  However,
 > now getline will leave the carriage return at the end of the line in the string
 > (which was not the case before).
 > 
 > >gcc -v
 > Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/gcc-2.95.2-9/specs
 > gcc version gcc-2.95.2-9 19991024 (cygwin experimental)
 > 
 > Thanks!
 
 Here's what I get with the following:
 
 #include <fstream>
 #include <iostream>
 #include <string>
 
 using namespace std;
 int main(int argc, char** argv)
 {
   ifstream in(argv[1]);
   string line;
   getline(in, line);
   cout << "0: " << line << endl;
   cout << "gcount = " << in.gcount() << endl;
   size_t pos = in.tellg();
   cout << "remember " << pos << endl;
   while (getline(in, line))
   {
     cout << "0: [" << line << ']' << endl;
   }
   in.clear();
   in.seekg(pos, ios::beg);
   cout << "restore " << in.tellg() << endl;
   while (getline(in, line))
   {
     cout << "1: [" << line << ']' << endl;
   }
 }
 
 %COMP.sh "-static" 2259.cpp
 <bkoz@fillmore>
 /mnt/hd/bliss/src.gcc/libstdc++-v3/testsuite                    %a.out 
 0: 
 gcount = 0
 remember 4294967295
 restore -1
 
 
 Again, I ask you to simplify. Please try to narrow down the problem. At
 least provide sample compile lines and invocation lines, and expected
 output?
 
 -benjamin
Comment 4 Benjamin Kosnik 2001-03-14 14:52:49 UTC
Responsible-Changed-From-To: unassigned->bkoz
Responsible-Changed-Why: responsible.
Comment 5 Benjamin Kosnik 2001-03-14 14:52:49 UTC
State-Changed-From-To: open->feedback
State-Changed-Why: cygwin-specific
Comment 6 Benjamin Kosnik 2001-03-14 22:52:49 UTC
From: bkoz@gcc.gnu.org
To: bkoz@gcc.gnu.org, gcc-gnats@gcc.gnu.org, hhuang@cs.columbia.edu,
  nobody@gcc.gnu.org
Cc:  
Subject: Re: libstdc++/2259
Date: 14 Mar 2001 22:52:49 -0000

 Synopsis: istream::tellg/seekg cause character loss
 
 Responsible-Changed-From-To: unassigned->bkoz
 Responsible-Changed-By: bkoz
 Responsible-Changed-When: Wed Mar 14 14:52:49 2001
 Responsible-Changed-Why:
     responsible.
 State-Changed-From-To: open->feedback
 State-Changed-By: bkoz
 State-Changed-When: Wed Mar 14 14:52:49 2001
 State-Changed-Why:
     cygwin-specific
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=2259&database=gcc
Comment 7 Benjamin Kosnik 2001-05-08 23:50:42 UTC
State-Changed-From-To: feedback->closed
State-Changed-Why: Fixed with current cygwin
Comment 8 Benjamin Kosnik 2001-05-09 06:50:42 UTC
From: bkoz@gcc.gnu.org
To: bkoz@gcc.gnu.org, gcc-gnats@gcc.gnu.org, hhuang@cs.columbia.edu
Cc:  
Subject: Re: libstdc++/2259
Date: 9 May 2001 06:50:42 -0000

 Synopsis: istream::tellg/seekg cause character loss
 
 State-Changed-From-To: feedback->closed
 State-Changed-By: bkoz
 State-Changed-When: Tue May  8 23:50:42 2001
 State-Changed-Why:
     Fixed with current cygwin
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=2259&database=gcc