public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* strstream
@ 1998-12-03 14:57 Thomas Matelich
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Matelich @ 1998-12-03 14:57 UTC (permalink / raw)
  To: egcs mailing list, tomsara

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 770 bytes --]

Are there any known bugs in strstream?  It seems like I'm getting a
memory overwrite.  I haven't been able to distill a smaller testcase
yet, but here is the offending code and the offensive output:

   ostrstream ss;
   ss << "T" << next_temp;
   string hold_it(ss.str());
   cout << "This temp channel will be named " << hold_it << endl;
   cout << "Here is the next line" << endl;

where next_temp is an unsigned int.

The output from this is:

This temp channel will be named T400000
-36.000000 -208.000000
-33.000000 -211.000000
-43.000000 -211.000000
-59.000000 -217.000000
-75.@ä
Here is the next line


Any suggestions (besides sprintf) would be appreciated.

--
Thomas O Matelich
Senior Programmer
Zetec, Inc.
tmatelich@zetec.com
tomsara@slip-stream.net





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

* Re: strstream
@ 1998-12-04  2:46 Klaus-Georg Adams
  0 siblings, 0 replies; 2+ messages in thread
From: Klaus-Georg Adams @ 1998-12-04  2:46 UTC (permalink / raw)
  To: tomsara; +Cc: egcs-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 916 bytes --]

Thomas wrote:
> Are there any known bugs in strstream?  It seems like I'm getting a
> memory overwrite.  I haven't been able to distill a smaller testcase
> yet, but here is the offending code and the offensive output:

The bug is in your code.

> 
>    ostrstream ss;
>    ss << "T" << next_temp;
>    string hold_it(ss.str());

The string ctor you use wants a pointer to a C-type (zero terminated)
string. You either have to zero terminate it ( ss << ends; ) or you
have use another ctor and  specify the length of the char*:
 string hold_it(ss.str(),ss.pcount());

-- kga
-------------------------------------------------------------------------
Klaus-Georg Adams        Email: Klaus-Georg.Adams@chemie.uni-karlsruhe.de
Institut f. Anorg. Chemie, Lehrstuhl II            Tel: 49(0)721 608 3485
Universität Karlsruhe, D-76128 Karlsruhe
-------------------------------------------------------------------------


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

end of thread, other threads:[~1998-12-04  2:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-12-03 14:57 strstream Thomas Matelich
1998-12-04  2:46 strstream Klaus-Georg Adams

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).