Permalink
Browse files

Correctly handle the case where 0 is passed to operator new.

  • Loading branch information...
1 parent fb8cc3b commit 02a01135a4d93c1e0029242f0889a59e6fe6beca David Chisnall committed Mar 28, 2012
Showing with 8 additions and 0 deletions.
  1. +8 −0 src/memory.cc
View
@@ -74,6 +74,10 @@ namespace std
__attribute__((weak))
void* operator new(size_t size)
{
+ if (0 == size)
+ {
+ size = 1;
+ }
void * mem = malloc(size);
while (0 == mem)
{
@@ -95,6 +99,10 @@ void* operator new(size_t size)
__attribute__((weak))
void* operator new(size_t size, const std::nothrow_t &) throw()
{
+ if (0 == size)
+ {
+ size = 1;
+ }
void *mem = malloc(size);
while (0 == mem)
{

0 comments on commit 02a0113

Please sign in to comment.