This is the mail archive of the gcc@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]
Other format: [Raw text]

Re: Integer overflow in operator new


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


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