summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2014-11-20 23:49:59 -0800
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2014-11-20 23:49:59 -0800
commit4b8da65be9f5adb340d7edf32362bdb24f20833b (patch)
tree25a35973d8d8d0f03f4f380217426b457194f6f3
parentdb8df4a5665cfb24c1c18be438d10b2e310a234e (diff)
Add allocator reserve for copying
Since copying no longer relies on child insertion we have to also reserve space in the hash table for the allocator so that pointer manipulations are guaranteed to succeed.
-rw-r--r--src/pugixml.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/pugixml.cpp b/src/pugixml.cpp
index 46653d1..16a012e 100644
--- a/src/pugixml.cpp
+++ b/src/pugixml.cpp
@@ -5680,7 +5680,10 @@ namespace pugi
xml_node_type type_ = proto.type();
if (!impl::allow_insert_child(type(), type_)) return xml_node();
- xml_node n(impl::allocate_node(impl::get_allocator(_root), type_));
+ impl::xml_allocator& alloc = impl::get_allocator(_root);
+ if (!alloc.reserve()) return xml_node();
+
+ xml_node n(impl::allocate_node(alloc, type_));
if (!n) return xml_node();
impl::append_node(n._root, _root);
@@ -5694,7 +5697,10 @@ namespace pugi
xml_node_type type_ = proto.type();
if (!impl::allow_insert_child(type(), type_)) return xml_node();
- xml_node n(impl::allocate_node(impl::get_allocator(_root), type_));
+ impl::xml_allocator& alloc = impl::get_allocator(_root);
+ if (!alloc.reserve()) return xml_node();
+
+ xml_node n(impl::allocate_node(alloc, type_));
if (!n) return xml_node();
impl::prepend_node(n._root, _root);
@@ -5709,7 +5715,10 @@ namespace pugi
if (!impl::allow_insert_child(type(), type_)) return xml_node();
if (!node._root || node._root->parent != _root) return xml_node();
- xml_node n(impl::allocate_node(impl::get_allocator(_root), type_));
+ impl::xml_allocator& alloc = impl::get_allocator(_root);
+ if (!alloc.reserve()) return xml_node();
+
+ xml_node n(impl::allocate_node(alloc, type_));
if (!n) return xml_node();
impl::insert_node_after(n._root, node._root);
@@ -5724,7 +5733,10 @@ namespace pugi
if (!impl::allow_insert_child(type(), type_)) return xml_node();
if (!node._root || node._root->parent != _root) return xml_node();
- xml_node n(impl::allocate_node(impl::get_allocator(_root), type_));
+ impl::xml_allocator& alloc = impl::get_allocator(_root);
+ if (!alloc.reserve()) return xml_node();
+
+ xml_node n(impl::allocate_node(alloc, type_));
if (!n) return xml_node();
impl::insert_node_before(n._root, node._root);