This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [C++] init.c/build_new wrongly implements new-expression


On May 25, 1999, Gabriel Dos_Reis <Gabriel.Dos_Reis@sophia.inria.fr> wrote:

> Alexandre Oliva <oliva@dcc.unicamp.br> writes:
> | On May 24, 1999, Gabriel Dos_Reis <Gabriel.Dos_Reis@sophia.inria.fr> wrote:
> | 
> | > So that the following ends up with a segmentation fault instead of
> | > throwing a bad_alloc:
> | 
> | > 	double* p = new double[numeric_limits<size_t>::max()];
> | 
> | It is correct.  It is not the allocation that fails, it's the size
> | calculation that overflows, thus producing undefined results.

> A possible fix would consist in having build_new insert a test to
> detect overflow and throw a bad_alloc. Thoughts?

A general principle of C++ is that you don't pay for what you don't
use.  Testing for overflow in every single new-expression might
introduce unacceptable overhead, while concerned users might (and
should) perform the test themselves, for the sake of portability.
Therefore, IMHO, gcc is not the proper place to introduce this fix.
Unless it is disabled by default, and is enabled with
-fcheck-overflow-on-new-array.  But I don't think it's worth it.

-- 
Alexandre Oliva http://www.dcc.unicamp.br/~oliva IC-Unicamp, Bra[sz]il
{oliva,Alexandre.Oliva}@dcc.unicamp.br  aoliva@{acm.org,computer.org}
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
*** E-mail about software projects will be forwarded to mailing lists


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]