LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-13-2009, 12:37 PM   #1
ineya
Member
 
Registered: Jul 2007
Posts: 39

Rep: Reputation: 16
Unhappy stringstream overwriting memory


I'm looking at a very strange problem in my work.
I'm working on a application, which runs on mips embedded device - this is making things difficult, because my favorite - 'valgrind' is not available here, and also electric fence has troubles to run.

I have:

static std::string s = "blahblah";

and

int SomeClass::someMethod()
{
stringstream h;
h << "Test";
}

and somehow the string 's' gets overwritten after calling stringstream:perator<<.

I suspect something bad has happened to stringstream or some allocator, which it is using prior to using operator<<. But I'm now struggling how to detect what is the cause.

Can you recommend any approach or give any advice how to track this down?

Last edited by ineya; 10-14-2009 at 04:40 AM.
 
Old 10-13-2009, 03:22 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
But which 's' is overwritten? std::string or stringstream?
 
Old 10-14-2009, 12:41 AM   #3
ineya
Member
 
Registered: Jul 2007
Posts: 39

Original Poster
Rep: Reputation: 16
my bad, I didn't notice, that I used the same identified for both,
string 's' gets overwritten

Code:
static std::string s = "blahblah";

int SomeClass::someMethod()
{
  stringstream h;
  h << "Test"; // after this line the string s is overwritten or cut by few characters
}
 
Old 10-14-2009, 12:54 AM   #4
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
this related?:http://www.gamedev.net/community/for...opic_id=338873
 
Old 10-14-2009, 01:44 AM   #5
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by ineya View Post
I'm looking at a very strange problem in my work.
I'm working on a application, which runs on mips embedded device - this is making things difficult, because my favorite - 'valgrind' is not available here, and also electric fence has troubles to run.

I have:

static std::string s = "blahblah";

and

int SomeClass::someMethod()
{
stringstream s;
s << "Test";
}

and somehow the string 's' gets overwritten after calling stringstream:perator<<.

I suspect something bad has happened to stringstream or some allocator, which it is using prior to using operator<<. But I'm now struggling how to detect what is the cause.

Can you recommend any approach or give any advice how to track this down?
You have two entities labeled 's' -- a string and a stringstream. Which one is being overwritten? You don't say. And you don't make their respective namespaces clear -- is the static string 's' a member of the class "SomeClass" or something else? Also, what Java version is in use?

To put this simply, if you think you're confused, consider how we feel -- we have much less reliable information than you do.
 
Old 10-14-2009, 12:43 PM   #6
ineya
Member
 
Registered: Jul 2007
Posts: 39

Original Poster
Rep: Reputation: 16
Problem was bug in toolchain,.. I found that by huge luck, not sure how would I get there just by debugging.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
FIle Overwriting ZAMO Linux - General 3 08-08-2007 10:46 AM
How to copy without overwriting [KIA]aze Linux - Newbie 4 03-08-2007 07:42 AM
stringstream problem deVas Programming 1 02-14-2007 09:05 PM
stringstream as class member variable xhi Programming 15 10-13-2006 11:52 AM
c++ stringstream greg108 Programming 7 06-24-2005 07:48 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration