tests: Assert on out-of-memory in tests
This should never happen but can improve debugging experience for work-in-progress changes since that avoids memcpy() into negative memory space (debugger can't backtrace from failed memcpy since it does not set up the stack frame). git-svn-id: https://pugixml.googlecode.com/svn/trunk@1070 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
parent
7774cdd96e
commit
7258aea09b
@ -1,6 +1,7 @@
|
|||||||
#include "allocator.hpp"
|
#include "allocator.hpp"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
// Low-level allocation functions
|
// Low-level allocation functions
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
@ -97,6 +98,8 @@ void* memory_allocate(size_t size)
|
|||||||
|
|
||||||
size_t memory_size(void* ptr)
|
size_t memory_size(void* ptr)
|
||||||
{
|
{
|
||||||
|
assert(ptr);
|
||||||
|
|
||||||
size_t result;
|
size_t result;
|
||||||
memcpy(&result, static_cast<size_t*>(ptr) - 1, sizeof(size_t));
|
memcpy(&result, static_cast<size_t*>(ptr) - 1, sizeof(size_t));
|
||||||
|
|
||||||
|
|||||||
@ -34,6 +34,7 @@ static void* custom_allocate(size_t size)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
void* ptr = memory_allocate(size);
|
void* ptr = memory_allocate(size);
|
||||||
|
assert(ptr);
|
||||||
|
|
||||||
g_memory_total_size += memory_size(ptr);
|
g_memory_total_size += memory_size(ptr);
|
||||||
g_memory_total_count++;
|
g_memory_total_count++;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user