From 973b905f39213b232c27bc6c7b219e8a1589d075 Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Wed, 15 Sep 2010 05:36:32 +0000 Subject: Added more assertions git-svn-id: http://pugixml.googlecode.com/svn/trunk@734 99668b35-9821-0410-8761-19e4c4f06640 --- src/pugixml.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 7326dcf..bcb0e89 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -115,6 +115,8 @@ namespace // Get string length size_t strlength(const char_t* s) { + assert(s); + #ifdef PUGIXML_WCHAR_MODE return wcslen(s); #else @@ -125,6 +127,8 @@ namespace // Compare two strings bool strequal(const char_t* src, const char_t* dst) { + assert(src && dst); + #ifdef PUGIXML_WCHAR_MODE return wcscmp(src, dst) == 0; #else @@ -277,11 +281,11 @@ namespace pugi void deallocate_memory(void* ptr, size_t size, xml_memory_page* page) { - assert(ptr >= page->data && ptr < page->data + xml_memory_page_size); - (void)!ptr; - if (page == _root) page->busy_size = _busy_size; + assert(ptr >= page->data && ptr < page->data + page->busy_size); + (void)!ptr; + page->freed_size += size; assert(page->freed_size <= page->busy_size); @@ -1344,6 +1348,7 @@ namespace if (end) // there was a gap already; collapse it { // Move [old_gap_end, new_gap_start) to [old_gap_start, ...) + assert(s >= end); memmove(end - size, end, reinterpret_cast(s) - reinterpret_cast(end)); } @@ -1360,6 +1365,7 @@ namespace if (end) { // Move [old_gap_end, current_pos) to [old_gap_start, ...) + assert(s >= end); memmove(end - size, end, reinterpret_cast(s) - reinterpret_cast(end)); return s - size; @@ -2346,6 +2352,7 @@ namespace } xml_parse_result result = make_parse_result(static_cast(error), parser.error_offset ? parser.error_offset - buffer : 0); + assert(result.offset >= 0 && static_cast(result.offset) <= length); // update allocator state *static_cast(xmldoc) = parser.alloc; -- cgit v1.2.3