This is the mail archive of the gcc-bugs@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]

libstdc++/2037: ostrstream, string & vector delivers 'garbage' output with cout



>Number:         2037
>Category:       libstdc++
>Synopsis:       ostrstream, string & vector delivers 'garbage' output with cout
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Feb 20 04:56:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Georg Ritter
>Release:        gcc 3.0, nightly built  2001-02-19, 2.95.2 19991024 (release)
>Organization:
>Environment:
Suse 7.0
>Description:
Extra characters appear after an ostrstream 
converted to a string and sent to cout.

Amount of "garbage" depends on elements added to 
a vector<> (intList in the sample code).

It gives:
** i4
@ÈRs@îÿÿÿíÿÿÿìÿÿÿëÿÿÿêÿÿÿéÿÿÿèÿÿÿçÿÿÿæÿÿÿåÿÿÿäÿÿÿãÿÿÿâÿÿÿáÿÿÿàÿÿÿßÿÿÿÞÿÿÿÝÿÿÿÜÿÿÿÛÿÿÿÚÿÿÿÙÿÿÿØÿÿÿ

instead of:
**             i4

>How-To-Repeat:
just compile with -lstdc++ and the execute.  
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="strstreamMemBug.cpp"
Content-Disposition: inline; filename="strstreamMemBug.cpp"

/*
  Output of a DEC with DIGITAL C++ V6.1-027 on DIGITAL UNIX V4.0 (Rev. 1229), as I expected it
  **             i4


-
  Output on Linux with gcc 2.95.2, lot of garbage 

  ** i4
  @ÈRs@îÿÿÿíÿÿÿìÿÿÿëÿÿÿêÿÿÿéÿÿÿèÿÿÿçÿÿÿæÿÿÿåÿÿÿäÿÿÿãÿÿÿâÿÿÿáÿÿÿàÿÿÿßÿÿÿÞÿÿÿÝÿÿÿÜÿÿÿÛÿÿÿÚÿÿÿÙÿÿÿØÿÿÿ


-
  Output on Linux with gcc-3_0-branch, nightly build on 2001-02-19 (statically linked), also garbage
  **        i4
  Ó
  
  ÿùÿÿÿøÿÿÿ÷ÿÿÿöÿÿÿ9

*/


#include <strstream>
#include <string>
#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;


class DataPrimitive
{
public:
  string getFormatstring() { return formatstring(); }

  string getHeader()
  {
    ostrstream a;
    a.setf( ios::right );
    a << "** " 
      << setw(15) << getFormatstring()
      << endl;
    return a.str();
  }

protected:
  virtual string formatstring() = 0;
};


class integerArray : public DataPrimitive
{
  vector<int>*intList;

public:
  integerArray() { intList = new vector<int>; }
  ~integerArray() { delete( intList ); }
	      
  void add( int value )  { intList -> push_back( value ); }

  string formatstring()
  {
    ostrstream a;
    a << "i" << 4 << endl;
    return a.str();
  }
};


int main()
{

  integerArray a; 

  for( int j=0; j<100; j++) a.add( -1 * j );
  cout << a.getHeader() << endl;

  return 0;
}




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