February 8, 2009

Bigger memory allocation than expected

Wrong function

void* allocateBytes(size_t size)
{
  if (size > MAX_SIZE)
    return NULL;

  return new void*[size];
}

Fixed function

void* allocateBytes(size_t size)
{
  if (size > MAX_SIZE)
    return (void*)NULL;

  return (void*)new char[size];
}
  This blog is written and maintained by Attila Suszter. Read in Feed Reader.