delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/08/10:30:50

From: "Luke Bishop" <lbishop AT calvin DOT stemnet DOT nf DOT ca>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: GCC Bug (HELP ME!!!!!)
Date: 8 Mar 1998 01:45:18 GMT
Organization: The Zone
Lines: 43
Message-ID: <01bd497a$b53921e0$4248a5c6@technoid>
References: <01bd4887$162bdc80$7348a5c6 AT technoid> <35019CDA DOT 6805 AT cam DOT org>
NNTP-Posting-Host: n072h066.thezone.net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

> It doesn't. I don't want to spoil the fun of founding a bug in GCC, but
> your source (with an #include <stdio.h> added to it) compiles fine and
> does not crash...

It's more subtle than that.  In fact, here is the REAL debugging code I
used to find this bug myself:

#include <malloc.h>
#include <stdio.h>
class mytestvar {
        public:
                virtual void testfn()
                {

                }
                void* operator new(size_t me)
                {
                        printf("The new me...\n");
                        printf("%ld\n",me);
                        return NULL;
                }
                mytestvar()
                {
                        printf("Constructed...\n");
                        printf("%ld\n",this);
                }
};
extern long something __asm__("__vt$9mytestvar");
main()
{
        printf("%ld\n",*(long*)NULL);
        mytestvar* c=new mytestvar;
        printf("%ld\n",(long)c);
        printf("%ld\n",*(long*)c);
        printf("%ld\n",&something);
}

	It will not crash, but it DOES change the value at NULL.  I think that
this still counts as a bug, as the default NEW operator dereferences a NULL
pointer.
	Also, the fact that the default NEW operator will dump if it runs out of
memory is a deviation from the ANSI C++ spec anyway.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019