We help IT Professionals succeed at work.

assigning string

learningunix
learningunix asked
on
Under heavy load system, can this every fail or assign empty.

std::string inStr;
func(inStr);
printf ("Str = %s", inStr.c_str())

void func (std::string& outString)
{
     outString.clear();
     std::string localString ("TEST");
     outString = localString; // can this every fail under heavy load.

     // I mean is it possible that outString will be empty under any case?
}
Comment
Watch Question

Owner, Lead Technology Programmer
Commented:
No - unless the assignment operator was written to intentionally not make the assignment under some circumstance, which I doubt is the case.

If it fails then it would have to be for another reason.  Memory overwrite?  Multi-threading issue?
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
Perhaps you have another naughty program that is not checking its bounds and overwriting memory in this program.

Author

Commented:

I am not sure what you mean by memory overwrite in this code?
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
No. In another program.
Bill NolanOwner, Lead Technology Programmer
Commented:
A memory overwrite occurs when you've written to memory that has been reserved for something else.  E.g., if you allocate memory for a discrete block of data, such as:

char* pStuff = malloc(1024)

...the memory manager sets that aside for your block of chararacters.  Other critical data may be stored immediately following this reserved block.  If you then proceed to write 2,000 characters at that location (pStuff), you will overwrite anything stored just beyond its declared borders.  This is the most insidious of errors, and can cause all kinds of unpredictable behaviour, and in particular is a strong candidate for the kind of error you mention here.

Note: The memory overwrite needn't be in another program; in fact, if that is your problem, it is much more likely that the overwrite IS in the same program.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.