Mail Archives: djgpp/1998/03/08/10:30:50
> 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 -