This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Integer overflow in operator new
- From: Gabriel Dos Reis <gdr at cs dot tamu dot edu>
- To: rridge at csclub dot uwaterloo dot ca (Ross Ridge)
- Cc: gcc at gcc dot gnu dot org
- Date: 07 Apr 2007 16:01:57 -0500
- Subject: Re: Integer overflow in operator new
- References: <20070407193620.2A401741BB@caffeine.csclub.uwaterloo.ca>
rridge@csclub.uwaterloo.ca (Ross Ridge) writes:
| Joe Buck writes:
| >If a check were to be implemented, the right thing to do would be to throw
| >bad_alloc (for the default new) or return 0 (for the nothrow new).
|
| Ross Ridge writes:
| >What do you do if the user has defined his own operator new that does
| >something else?
|
| Gabriel Dos Reis writes:
| >More precisely?
|
| Well, for example, like all other things that a new_handler can do,
| like throwing an exception derived from bad_alloc or calling exit().
| In addition, any number of side effects are possible, like printing
| error messages or setting flags.
I believe you're confused about the semantics.
The issue here is that the *size of object* requested can be
represented. That is independent of whether the machine has enough
memory or not. So, new_handler is a red herring.
-- Gaby