This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: FW: ostringstream: problems with str() function
- From: Michael Veksler <mveksler at techunix dot technion dot ac dot il>
- To: "Jordan, Laszlo (GE Healthcare)" <Laszlo dot Jordan at ge dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Thu, 24 Aug 2006 21:33:32 +0300
- Subject: Re: FW: ostringstream: problems with str() function
- References: <5B122FD931231D408AC32630D1B1F7290D6304A3@BUDMLVEM03.e2k.ad.ge.com>
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