From ea0dbe78843fa8b5e4c1d3f247383e38fb2348ef Mon Sep 17 00:00:00 2001
From: "arseny.kapoulkine"
 <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>
Date: Sun, 29 Aug 2010 15:20:27 +0000
Subject: tests: Deallocation of null pointer is illegal for custom allocators

git-svn-id: http://pugixml.googlecode.com/svn/trunk@656 99668b35-9821-0410-8761-19e4c4f06640
---
 tests/main.cpp | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/tests/main.cpp b/tests/main.cpp
index 2af0a55..dc2a487 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -6,6 +6,7 @@
 #include <iostream>
 #include <stdio.h>
 #include <float.h>
+#include <assert.h>
 
 test_runner* test_runner::_tests = 0;
 size_t test_runner::_memory_fail_threshold = 0;
@@ -32,13 +33,12 @@ static void* custom_allocate(size_t size)
 
 static void custom_deallocate(void* ptr)
 {
-	if (ptr)
-	{
-		g_memory_total_size -= memory_size(ptr);
-		g_memory_total_count--;
-		
-		memory_deallocate(ptr);
-	}
+	assert(ptr);
+
+	g_memory_total_size -= memory_size(ptr);
+	g_memory_total_count--;
+	
+	memory_deallocate(ptr);
 }
 
 static void replace_memory_management()
@@ -89,22 +89,22 @@ void* operator new[](size_t size, const std::nothrow_t&) throw()
 
 void operator delete(void* ptr) DECL_NOTHROW()
 {
-    custom_deallocate(ptr);
+    if (ptr) custom_deallocate(ptr);
 }
 
 void operator delete[](void* ptr) DECL_NOTHROW()
 {
-    custom_deallocate(ptr);
+    if (ptr) custom_deallocate(ptr);
 }
 
 void operator delete(void* ptr, const std::nothrow_t&) throw()
 {
-    custom_deallocate(ptr);
+    if (ptr) custom_deallocate(ptr);
 }
 
 void operator delete[](void* ptr, const std::nothrow_t&) throw()
 {
-    custom_deallocate(ptr);
+    if (ptr) custom_deallocate(ptr);
 }
 
 #if defined(_MSC_VER) && _MSC_VER > 1200 && _MSC_VER < 1400 && !defined(__INTEL_COMPILER) && !defined(__DMC__)
-- 
cgit v1.2.3