From ac150d504e0e1fa54eb042325c87f08740f1d4f6 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Mon, 30 Jan 2017 21:45:01 -0800 Subject: XPath: Throw std::bad_alloc if we got an out-of-memory error This allows us to gradually convert exception handling of out-of-memory during evaluation to a non-throwing approach without changing the observable behavior. --- src/pugixml.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/pugixml.cpp b/src/pugixml.cpp index c6fee40..2e25551 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -11870,6 +11870,10 @@ PUGI__NS_BEGIN xpath_string r = impl->root->eval_string(c, sd.stack); + #ifndef PUGIXML_NO_EXCEPTIONS + if (sd.error) throw std::bad_alloc(); + #endif + return sd.error ? xpath_string() : r; } @@ -12510,6 +12514,10 @@ namespace pugi bool r = static_cast(_impl)->root->eval_boolean(c, sd.stack); + #ifndef PUGIXML_NO_EXCEPTIONS + if (sd.error) throw std::bad_alloc(); + #endif + return sd.error ? false : r; } @@ -12526,6 +12534,10 @@ namespace pugi double r = static_cast(_impl)->root->eval_number(c, sd.stack); + #ifndef PUGIXML_NO_EXCEPTIONS + if (sd.error) throw std::bad_alloc(); + #endif + return sd.error ? impl::gen_nan() : r; } @@ -12574,6 +12586,10 @@ namespace pugi impl::xpath_node_set_raw r = root->eval_node_set(c, sd.stack, impl::nodeset_eval_all); + #ifndef PUGIXML_NO_EXCEPTIONS + if (sd.error) throw std::bad_alloc(); + #endif + return sd.error ? xpath_node_set() : xpath_node_set(r.begin(), r.end(), r.type()); } @@ -12591,6 +12607,10 @@ namespace pugi impl::xpath_node_set_raw r = root->eval_node_set(c, sd.stack, impl::nodeset_eval_first); + #ifndef PUGIXML_NO_EXCEPTIONS + if (sd.error) throw std::bad_alloc(); + #endif + return sd.error ? xpath_node() : r.first(); } -- cgit v1.2.3