This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: FW: ostringstream: problems with str() function


Jordan, Laszlo (GE Healthcare) wrote:
Hi,
I had a crash in our software, which occured randomly. The valgrind logs
and the stack trace pointed to a code snippet, which uses ostringstream
for data conversion. (int -> string, float -> string, double-> string).
After changing the ostringstream conversion to sprintf, the crash in the
application no more occured and the valgrind log was clear as well. It
seems the problem is in the str() function of ostringstream.
Consider the following test program in order to reproduce the bug:
#include <iostream>
#include <strstream>
#include <sstream>
#include <vector>
#include <string>
int main()
{
std::vector<std::string> v;
{
std::ostringstream sstr;
sstr << (double)1.12;
v.push_back(sstr.str());
}
return 1;
}


The problem occured with gcc 3.4.2 and 3.4.4 compilers with -O2
optimization. Test program had been running both on 32 and 64 bit
architecture.
Can't reproduce neither with gcc-3.4.3 on Linux/x86 nor on AIX.

Michael


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