public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Bug in G++?
@ 2000-11-27  4:03 Kári Davíðsson
  0 siblings, 0 replies; 2+ messages in thread
From: Kári Davíðsson @ 2000-11-27  4:03 UTC (permalink / raw)
  To: Gcc help maillist (E-mail)

Hi,

I am not shure if this is the right mailing list to ask. If not redirect
me to the correct forum.


Anyway the following minimal c++ program (crash) crashes for me in the
delete line, line 25, if Vectorsize is larger than 3. While the program
"run" seem to run without problems. Is there a known fix for this bug,
except for the obvius to skip the declaration/definition of the default
contructor and destructor?

The backtrace from gdb is:
(gdb) bt
#0  0x400c9b26 in free () from /lib/libc.so.6
#1  0x400c9a0d in free () from /lib/libc.so.6
#2  0x4003e434 in __builtin_delete () from
/usr/lib/libstdc++-libc6.1-2.so.3
#3  0x8048659 in _._7MyClass (this=0x80499e4, __in_chrg=3) at crash.c:17
#4  0x8048714 in main (argc=1, argv=0xbffffce4) at crash.c:25

g++ is
bash-2.03$ g++ --version
2.95.2

Compile with g++ crash.c -o crash -g -DVECTORSIZE=4

Thanks,

K.D.

//Program crash begins
#include <stdio.h>

class MyClass
{
public:
	MyClass();
	~MyClass();
private:
	int i;
};

MyClass::MyClass(void)
{
};

MyClass::~MyClass(void)
{
};

int main(int argc, char** argv)
{
	MyClass * ptr;
	ptr = new MyClass[VECTORSIZE];
	delete ptr;
}

//Program carsh ends

//Program run begins
#include <stdio.h>

class MyClass
{
private:
	int i;
};

int main(int argc, char** argv)
{
	MyClass * ptr;
	ptr = new MyClass[VECTORSIZE];
	delete ptr;
}
//Program run ends

^ permalink raw reply	[flat|nested] 2+ messages in thread

* RE: Bug in G++?
@ 2000-11-27  4:52 David Korn
  0 siblings, 0 replies; 2+ messages in thread
From: David Korn @ 2000-11-27  4:52 UTC (permalink / raw)
  To: 'Kári
	Davíðsson',
	Gcc help maillist (E-mail)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1295 bytes --]

>-----Original Message-----
>From: Kári Davíðsson [ mailto:kd@flaga.is ]
>Sent: 27 November 2000 12:02
>To: Gcc help maillist (E-mail)
>Subject: Bug in G++? 

>int main(int argc, char** argv)
>{
>	MyClass * ptr;
>	ptr = new MyClass[VECTORSIZE];
>	delete ptr;
>}

  When allocating with operator new[], you MUST use operator delete[] to get
rid of the array of objects. Although one version of your code runs 
successfully, it's just luck.

   hth, 
      DaveK
-- 
The Boulder Pledge: "Under no circumstances will I ever purchase anythingo
 ffered to me as the result of an unsolicited email message. Nor will I 
forward chain letters, petitions, mass mailings, or virus warnings to largen
 umbers of others. This is my contribution to the survival of the online
community."


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-11-27  4:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-27  4:03 Bug in G++? Kári Davíðsson
2000-11-27  4:52 David Korn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).