summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/pugixml.cpp28
-rw-r--r--tests/test_dom_modify.cpp14
2 files changed, 32 insertions, 10 deletions
diff --git a/src/pugixml.cpp b/src/pugixml.cpp
index 7c640de..eff6760 100644
--- a/src/pugixml.cpp
+++ b/src/pugixml.cpp
@@ -5602,7 +5602,10 @@ namespace pugi
if (!proto) return xml_attribute();
if (!impl::allow_insert_attribute(type())) return xml_attribute();
- xml_attribute a(impl::allocate_attribute(impl::get_allocator(_root)));
+ impl::xml_allocator& alloc = impl::get_allocator(_root);
+ if (!alloc.reserve()) return xml_attribute();
+
+ xml_attribute a(impl::allocate_attribute(alloc));
if (!a) return xml_attribute();
impl::append_attribute(a._attr, _root);
@@ -5616,7 +5619,10 @@ namespace pugi
if (!proto) return xml_attribute();
if (!impl::allow_insert_attribute(type())) return xml_attribute();
- xml_attribute a(impl::allocate_attribute(impl::get_allocator(_root)));
+ impl::xml_allocator& alloc = impl::get_allocator(_root);
+ if (!alloc.reserve()) return xml_attribute();
+
+ xml_attribute a(impl::allocate_attribute(alloc));
if (!a) return xml_attribute();
impl::prepend_attribute(a._attr, _root);
@@ -5631,7 +5637,10 @@ namespace pugi
if (!impl::allow_insert_attribute(type())) return xml_attribute();
if (!attr || !impl::is_attribute_of(attr._attr, _root)) return xml_attribute();
- xml_attribute a(impl::allocate_attribute(impl::get_allocator(_root)));
+ impl::xml_allocator& alloc = impl::get_allocator(_root);
+ if (!alloc.reserve()) return xml_attribute();
+
+ xml_attribute a(impl::allocate_attribute(alloc));
if (!a) return xml_attribute();
impl::insert_attribute_after(a._attr, attr._attr, _root);
@@ -5646,7 +5655,10 @@ namespace pugi
if (!impl::allow_insert_attribute(type())) return xml_attribute();
if (!attr || !impl::is_attribute_of(attr._attr, _root)) return xml_attribute();
- xml_attribute a(impl::allocate_attribute(impl::get_allocator(_root)));
+ impl::xml_allocator& alloc = impl::get_allocator(_root);
+ if (!alloc.reserve()) return xml_attribute();
+
+ xml_attribute a(impl::allocate_attribute(alloc));
if (!a) return xml_attribute();
impl::insert_attribute_before(a._attr, attr._attr, _root);
@@ -6010,7 +6022,7 @@ namespace pugi
for (xml_node_struct* i = _root; i; i = i->parent)
{
offset += (i != _root);
- offset += i->name ? impl::strlength(i->name) : 0;
+ offset += (impl::has_name(i) && i->contents) ? impl::strlength(i->contents) : 0;
}
string_t result;
@@ -6021,12 +6033,12 @@ namespace pugi
if (j != _root)
result[--offset] = delimiter;
- if (j->name && *j->name)
+ if (impl::has_name(j) && j->contents && *j->contents)
{
- size_t length = impl::strlength(j->name);
+ size_t length = impl::strlength(j->contents);
offset -= length;
- memcpy(&result[offset], j->name, length * sizeof(char_t));
+ memcpy(&result[offset], j->contents, length * sizeof(char_t));
}
}
diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp
index 47c4a04..071b798 100644
--- a/tests/test_dom_modify.cpp
+++ b/tests/test_dom_modify.cpp
@@ -1115,6 +1115,11 @@ TEST(dom_node_append_buffer_out_of_memory_nodes)
test_runner::_memory_fail_threshold = 32768 + 128 + data.length() * sizeof(char_t) + 32;
+#ifdef PUGIXML_COMPACT
+ // ... and some space for hash table
+ test_runner::_memory_fail_threshold += 2048;
+#endif
+
xml_document doc;
CHECK_ALLOC_FAIL(CHECK(doc.append_buffer(data.c_str(), data.length() * sizeof(char_t), parse_fragment).status == status_out_of_memory));
@@ -1131,9 +1136,9 @@ TEST(dom_node_append_buffer_out_of_memory_nodes)
TEST(dom_node_append_buffer_out_of_memory_name)
{
- test_runner::_memory_fail_threshold = 32768 + 128;
+ test_runner::_memory_fail_threshold = 32768 + 4096;
- char data[128] = {0};
+ char data[4096] = {0};
xml_document doc;
CHECK(doc.append_child(STR("root")));
@@ -1459,6 +1464,11 @@ TEST(dom_node_copy_attribute_copyless)
// the document is parsed in-place so there should only be 1 page worth of allocations
test_runner::_memory_fail_threshold = 32768 + 128;
+#ifdef PUGIXML_COMPACT
+ // ... and some space for hash table
+ test_runner::_memory_fail_threshold += 2048;
+#endif
+
xml_document doc;
CHECK(doc.load_buffer_inplace(&datacopy[0], datacopy.size() * sizeof(char_t), parse_full));