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. Solved?


On 4/9/07, J.C. Pizarro <jcpiza@gmail.com> wrote:
#include <stddef.h>

void *__allocate_array_OptionA(size_t num, size_t size) { // 1st best
   unsigned long long tmp = (unsigned long long)size * num;
   if (tmp >= 0x0000000080000000ULL) tmp=~size_t(0);
   return operator new[](tmp);
}

First this just happens to be the best for x86, what about PPC or really any embedded target where people are more concern about code size than say x86.

Also what about x86_64 where sizeof(size_t) == sizeof(unsigned long
long) so this trick is not going to work

-- Pinski


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