This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

strstream bug



  Greetings,
 
     We are using an out-of-the-tarball g++2.95.1 on Solaris
  and Linux, and had a weird problem with strstream while
  porting code that otherwise compiles with CC4.2. Failed
  regression tests attracted attention, and I am appending
  two emails describing problems and workarounds (the second
  is somewhat more legible). 
     Would anyone please check that those problems do not
  happen with the new [unfinished] libstdc++ ? (or, if they
  are not bugs, I'd appreciate that info + explanations).

   thanks a lot,     
						Igor
------------------------------------------------------------
Mike Oliver wrote
> I found a way around the strstream bug (is it a bug?) which seems
> genuinely to avoid it rather than finding a separate bug(?) which
> works around it.  The alleged bug is that if you do the following:
> 
>        char *s=new char[10];
>        strcpy(s,"012345678");
>        strstream sts(s,strlen(s));
> 
> for some reason on g++ you cannot read from this stream.  But if you
> change the third line to
> 
>        strstream sts(s,strlen(s),ios::ate);
> 
> then the "get" pointer is correctly set to the beginning of the string --
> a *bizarre* result given that I suspect "ate" stands for "append to end".
> (The "put" pointer should be set to the end of the string.)
> 
> The better workaround is, instead of strstream, use istrstream :
> 
>       istrstream sts(s);
> 
> Now really I would rather use stringstream, but for some reason g++ doesn't
> know about it.  I even went to the include directory for g++ and grep'd
> the whole thing, and it just wasn't there.  That's assuming I'm right
> that the include directory is 
> /opt/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.1/include/g++ .

Andrew Caldwell wrote
> 
> 
> The following causes problems w/ g++:
> 
> 
> strstream s;
> FixedGraph f0(0);
> s<<f0;
> s>>f0;
> 
> RigidGraph r0(0);
> s<<r0;
> s>>r0;
> 
> ..it complains when it gets to reading into the second graph (RigidGraph) ..
> it looks as though the read pointer is in the wrong location.
> 
> using a new strstream solves the problem:
> 
> strstream s;
> FixedGraph f0(0);
> s<<f0;
> s>>f0;
> 
> strstream s2;
> RigidGraph r0(0);
> s2<<r0;
> s2>>r0;
> 
> mike's problem appears related to the read pointer, too..he
> was able to solve it by opening the file in ios:ate mode
> (opens the file & then calls seek(ios::eof)).


-- 
  Igor Markov  office: (310) 206-0179   
  http://vlsicad.cs.ucla.edu/~imarkov

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]