Subject: Bug#4011: simple c++ program segfaults

From: Herbert Xu <[email-masked]>
Date: Sat, 3 Aug 1996 19:46:22 +1000 (EST)

Package: gcc
Version: 2.7.2-8

A recent posting on comp.os.linux.apps by
[email-masked] (Dirk Alboth) can
be reproduced on my Debian system.  In fact,
it seems to occur on a Sun with g++ too.

Here's a modified version of the program:

--
#include <fstream.h>

void main( int argc, char **argv) {
  ofstream ofst;
  ofst.ofstream( argv[1]);
  ofst.form( "%s\n", "Hello world");
  ofst.~ofstream();
}
--

Running it with the argument of 'test' produces
a segfault.

-- 
Debian GNU/Linux 1.1 is out! { http://www.debian.org/ }
A.  B <=> True			B.  A <=> False
Email:  Herbert Xu ~{PmV>HI~} <[email-masked]>
PGP Key:  [email-masked] or any other key sites

---

From: Rob Browning <[email-masked]>
Date: 04 Aug 1996 23:46:54 -0500

>   ofst.form( "%s\n", "Hello world");

Is this actually a bug?  I don't think you are supposed to call a
destructor directly in this situation.  I would assume that the crash
comes when the destructor is called a second time when the program
exits main.

--
Rob

---

From: Guy Maor <[email-masked]>
Date: Tue, 6 Aug 1996 14:43:15 -0500 (CDT)

> comes when the destructor is called a second time when the program

It is legal to explicitly call a destructor but rarely needed.  It
certainly makes no sense in this case, as the destructor will be called
twice.

The question, it seems, is what was the programmer trying to do?

Guy

---

From: Herbert Xu <[email-masked]>
Date: Wed, 7 Aug 1996 10:26:20 +1000 (EST)

> The question, it seems, is what was the programmer trying to do?

Well I haven't got a clue on that one as I didn't write the code.  But
I guess the more important question is that the crash did not seem to
be related to the destructor.  That is, it crashes even without the call
to the destructor.

-- 
Debian GNU/Linux 1.1 is out! { http://www.debian.org/ }
A.  B <=> True			B.  A <=> False
Email:  Herbert Xu 许志壬 <[email-masked]>
PGP Key:  [email-masked] or any other key sites

---

From: "Brian C. White" <[email-masked]>
Date: Tue, 06 Aug 1996 23:09:34 -0400

> certainly makes no sense in this case, as the destructor will be called

It is legal, but highly discouraged!  If the dtor is not implemented
with
this in mind (as most are not), then that could very easily be the cause
of the seg fault.

                                        Brian
                               ( [email-masked] )

-------------------------------------------------------------------------------
    In theory, theory and practice are the same.  In practice, they're
not.