From a6c756b8bce21d88db10fdeffcb5e87c7d66c6b9 Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Sun, 3 Oct 2010 14:27:52 +0000 Subject: XPath: If exceptions are enabled, std::bad_alloc is thrown for all out of memory situation (instead of xpath_exception) git-svn-id: http://pugixml.googlecode.com/svn/trunk@759 99668b35-9821-0410-8761-19e4c4f06640 --- src/pugixml.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/pugixml.cpp b/src/pugixml.cpp index b6b4f17..903416c 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -8196,11 +8196,20 @@ namespace pugi #endif } + void throw_error_oom() + { + #ifdef PUGIXML_NO_EXCEPTIONS + throw_error("Out of memory"); + #else + throw std::bad_alloc(); + #endif + } + void* alloc_node() { void* result = _alloc->allocate_nothrow(sizeof(xpath_ast_node)); - if (!result) throw_error("Out of memory"); + if (!result) throw_error_oom(); return result; } @@ -8212,7 +8221,7 @@ namespace pugi size_t length = static_cast(value.end - value.begin); char_t* c = static_cast(_alloc->allocate_nothrow((length + 1) * sizeof(char_t))); - if (!c) throw_error("Out of memory"); + if (!c) throw_error_oom(); memcpy(c, value.begin, length * sizeof(char_t)); c[length] = 0; @@ -8489,7 +8498,7 @@ namespace pugi double value = 0; if (!convert_string_to_number(_lexer.contents().begin, _lexer.contents().end, &value)) - throw_error("Out of memory"); + throw_error_oom(); xpath_ast_node* n = new (alloc_node()) xpath_ast_node(ast_number_constant, xpath_type_number, value); _lexer.next(); @@ -9224,10 +9233,10 @@ namespace pugi if (!alloc) { + #ifdef PUGIXML_NO_EXCEPTIONS _result.error = "Out of memory"; - - #ifndef PUGIXML_NO_EXCEPTIONS - throw xpath_exception(_result); + #else + throw std::bad_alloc(); #endif } else -- cgit v1.2.3