www.delorie.com/djgpp/bugs/show.cgi   search  
Bug 000211

When Created: 03/03/1998 17:56:42
Against DJGPP version: 2.01
By whom: nanosoft@nanosoft.hypermart.net
Abstract: Bug in operator new
The 'new' operator in C++ has a severe bug.  According to the ANSI C++ specification, 'new' can now return NULL on failure.  The DJGPP standard operator 'new' will just exit to DOS on failure, but if it is overloaded, the operator can now return NULL.  In this case, the vftbl is written to the NULL address.

Example:

class test {
  public:
         virtual void me() {};
         void* operator new(size_t s)
         {
                  return malloc(s);
         }
};

 If malloc returns NULL, this program overwrites NULL.  This bug is somewhere in GCC.

Note added: 12/02/1998 13:00:02
By whom: stekman@earthling.net
Are you sure? This is what is told in the December -96 draft:

A new_handler shall perform one of the following:

  --make more storage available for allocation and then return;

  --throw an exception  of  type  bad_alloc  or  a  class  derived  from
    bad_alloc;

  --call either abort() or exit();

Default behavior:
    The implementation's default new_handler throws an exception of type
    bad_alloc.

Closed on 04/13/1999 07:00:49: Not a bug; and even if it is, it's in the C++ library, not in DJGPP.
By whom: eliz@is.elta.co.il



  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2010   by DJ Delorie     Updated Jul 2010