🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.lib.bug
Article #454

2.3: ostrstream and freeze

#454
From: Doug Moore
Date: Tue, 26 Jan 1993 01:49
73 lines
2817 bytes
Unfreezing a previously frozen (with str) ostrstream, when that
ostrstream has a fixed, user-supplied buffer, causes the ostrstream
destructor to inappropriately delete the user-supplied buffer.

The program that follows should print, in an endless sequence,
"Hello!" and a memory address.  And with the Sun C++ implementation of
strstreams, it does.  With libg++, it crashes after the first
iteration.

Sun sparc.  Sunos 4.1.2.  g++ 2.3.3, with patches.  libg++ 2.3, with
patches.  Verbose compiler output:
======================================================================
g++ jnk.cc -o a.out -g -v -Wall
Reading specs from /blossom/lib/gcc-lib/sun4/2.3.3/specs
gcc version 2.3.3
 /blossom/lib/gcc-lib/sun4/2.3.3/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix -g -Wall jnk.cc /usr/tmp/cca07996.i
GNU CPP version 2.3.3 (sparc)
 /blossom/lib/gcc-lib/sun4/2.3.3/cc1plus /usr/tmp/cca07996.i -quiet -dumpbase jnk.cc -g -Wall -version -o /usr/tmp/cca07996.s
GNU C++ version 2.3.3 (sparc) compiled by GNU C version 2.3.3.
 as -o /usr/tmp/cca079961.o /usr/tmp/cca07996.s
 /blossom/lib/gcc-lib/sun4/2.3.3/ld -e start -dc -dp -o a.out /lib/crt0.o -L/blossom/lib/gcc-lib/sun4/2.3.3 -L/blossom/lib /usr/tmp/cca079961.o -lg++ -lgcc -lc -lg -lgcc

======================================================================

libg++ program output

======================================================================

0xf7fff6c8
Hello!
Segmentation fault

======================================================================

sun c++ program output (abbreviated)

======================================================================

Hello!
0xf7fff6dc
Hello!
0xf7fff6dc
Hello!
0xf7fff6dc

======================================================================

Program source:

======================================================================

#include <iostream.h>
#include <strstream.h>

int main(int, char*[])
{
  for(;;)
    {
      char buf[100];
      ostrstream strut(buf, sizeof(buf));
      strut << "Hello!" << ends;
      char *s = strut.str();
      cout << (void*)s << endl;
      cout << s << endl;
      strut.rdbuf()->freeze(0);
    }
  return 0;
}

======================================================================

Doug Moore
(dougm@cs.rice.edu)
Technical Details
Message-ID: <9301250337.AA08048@cs.rice.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cs.rice.edu!dougm

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cs.rice.edu!dougm
From: dougm@cs.rice.edu (Doug Moore)
Newsgroups: gnu.g++.lib.bug
Subject: 2.3: ostrstream and freeze
Date: 25 Jan 1993 20:49:24 -0500
Organization: GNUs Not Usenet
Lines: 74
Sender: daemon@cis.ohio-state.edu
Approved: bug-lib-g++@prep.ai.mit.edu
Distribution: gnu
Message-ID: <9301250337.AA08048@cs.rice.edu>