[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Unidentified subject!



Thanks for the thoughts.  I commented out the rdbuff->setbuf line and it
works much better now.

Also, I did post to comp.lang.c++.moderated too--yours and one other
message were the first responses I got--proving that the debian list is a
wonderful resource.

-bob


On Thu, Aug 26, 1999 at 10:03:21PM -0600, Robert Kerr wrote:
> Hi all,
> I'm having some problems converting my app to run under linux.  It runs
> alright under SGI, HP-UX, Solaris and WinNT, but it crashes beautifully
> under linux.
> 
> Anyway, I have a member variable called journalString of type
ostrstream.
> I instantiate it so:
>     journalString = new ostrstream();
>     journalString->rdbuf()->setbuf(NULL, 50);
> 
> but when I try to use the << operator with it, it Segfaults.
> Example crashes:
> 
> *journalString << ends;
> *journalString << s << ' '; where s is a const char *
> *journalString << name;  where name is a const char *
> 
> Am I using ostrstream wrong?  Any ideas?

It looks to me as if you are doing too complicated things.  Is the
rdbuf->setbuf(NULL, 50) meant to allocated memory?  You don't need to do
that, the class is designed to take care of that by itself.

Is there a reason to have a member ostrstream pointer, instead of just
an ostrstream?  Typical use would be something like

ostrstream* journalString = new ostrstream();
string s = "something";
*journalString << "bla" << ' ' << s << ends;

journalString->c_str() returns the buffer as a C style string (char*).
If you use that, you need to deallocate the memory pointed to by c_str()
yourself, unless you later call

journalString->freeze(0);

Note that in the future the ostrstream will be replaced by
ostringstream.

Finally, segmentation faults can be due to memory corruption happening
elsewhere in the program, and only triggered in your ostrstream lines.
The fact that a program does not crash on other platforms does not mean
there are no bugs.  It is well possible that a memory corrupting bug
only bites you in linux.

HTH,
Eric

BTW, this is more of a question for a C++ newsgroup, like
comp.lang.c++.moderated.



-- 
-bob

You know you've landed with the wheels up when it takes full power
to taxi.
**********************************************************************
* Robert Kerr, The morphing guy.  *    368 Clyde Building, BYU       *
* rakerr@sandia.gov               *        Provo, Utah  84602        *
* Robert_Kerr@byu.edu             *      Phone: (801) 378-2029       *
* http://www.et.byu.edu/~kerrr    *      Fax: (801) 378-4449         *
**********************************************************************




Reply to: