Name

DEFECT_GCC27_STRINGSTREAM_STR


Affected Systems-Compilers

Systems: all

Compilers: GNU C++ 2.7


Description

The method stringstream::str() can return an incorrectly formed string, with one to three garbage characters at the end.


Work-Around

#if defined(DEFECT_OLD_STRINGSTREAM)

#include <strstream.h>

#define ostringstream ostrstream // Avoid having two types where only one is required

#else // Standard C++

#include <sstream>

#endif

string result ;

ostringstream type_string ;

type_string << "some text" ;

#if defined(DEFECT_GCC27_STRINGSTREAM_STR)

type_stream << '\0' ; \\ Manually null-terminate the stringstream

result = string(type_stream.str()) ;

#else // Standard C++

result = type_stream.str() ;

#endif