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



The assert should not overflow. I suggest


#include <stdlib.h>
#include <stdint.h>
assert( n < SIZE_MAX / sizeof(int) );

which requires two pieces of information that the programmer
otherwise wouldn't need, SIZE_MAX and sizeof(type).

Asking programmers to write extra code for rare events, has
not been very successful.  It would be better if the compiler
incorporated this check into operator new, though throwing
an exception rather than asserting.  The compiler should be
able to eliminate many of the conditionals.

--
Lawrence Crowl

The operator new is reused many times as many callers. So, the programmers don't have many times to write extra code for calling into operator new.

The compiler should be able to eliminate many of the conditionals.
Yes but no, there are cases that the compiler can't eliminate the
conditionals that depend on run-time, e.g., "n" is non-constant parameter.

J.C. Pizarro


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