From b5556f184f3ea6f0c88820a486a843c471d612cc Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Mon, 11 Aug 2014 00:13:47 +0000 Subject: Move attribute name setup after pointer setup to handle exceptions better git-svn-id: https://pugixml.googlecode.com/svn/trunk@1005 99668b35-9821-0410-8761-19e4c4f06640 --- src/pugixml.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/pugixml.cpp b/src/pugixml.cpp index cc19c8a..b4255bd 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -4593,6 +4593,7 @@ namespace pugi if (type() != node_element && type() != node_declaration) return xml_attribute(); xml_attribute a(impl::append_new_attribute(_root, impl::get_allocator(_root))); + a.set_name(name_); return a; @@ -4605,8 +4606,6 @@ namespace pugi xml_attribute a(impl::allocate_attribute(impl::get_allocator(_root))); if (!a) return xml_attribute(); - a.set_name(name_); - xml_attribute_struct* head = _root->first_attribute; if (head) @@ -4619,7 +4618,9 @@ namespace pugi a._attr->next_attribute = head; _root->first_attribute = a._attr; - + + a.set_name(name_); + return a; } @@ -4637,8 +4638,6 @@ namespace pugi xml_attribute a(impl::allocate_attribute(impl::get_allocator(_root))); if (!a) return xml_attribute(); - a.set_name(name_); - if (attr._attr->prev_attribute_c->next_attribute) attr._attr->prev_attribute_c->next_attribute = a._attr; else @@ -4648,6 +4647,8 @@ namespace pugi a._attr->next_attribute = attr._attr; attr._attr->prev_attribute_c = a._attr; + a.set_name(name_); + return a; } @@ -4665,8 +4666,6 @@ namespace pugi xml_attribute a(impl::allocate_attribute(impl::get_allocator(_root))); if (!a) return xml_attribute(); - a.set_name(name_); - if (attr._attr->next_attribute) attr._attr->next_attribute->prev_attribute_c = a._attr; else @@ -4676,6 +4675,8 @@ namespace pugi a._attr->prev_attribute_c = attr._attr; attr._attr->next_attribute = a._attr; + a.set_name(name_); + return a; } -- cgit v1.2.3