Mercurial > sumwars
changeset 2707:b4777452361f
refs #105: Fixes coverity issue 1197034
author | Augustin Preda |
---|---|
date | Thu, 10 Apr 2014 21:32:12 +0300 |
parents | a37a2d95d34d |
children | 5b354db08e90 |
files | src/core/fixedbase.cpp src/gui/contenteditor/fixedobjecteditor.cpp |
diffstat | 2 files changed, 21 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/core/fixedbase.cpp Thu Apr 10 21:10:58 2014 +0300 +++ b/src/core/fixedbase.cpp Thu Apr 10 21:32:12 2014 +0300 @@ -40,27 +40,32 @@ elem->SetAttribute("layer","NOCOLLISION"); } + TiXmlNode* linkedNode = NULL; TiXmlElement* geom_node = elem->FirstChildElement("Geometry"); if (geom_node == 0) { geom_node = new TiXmlElement("Geometry"); - elem->LinkEndChild(geom_node); + linkedNode = elem->LinkEndChild(geom_node); } - if (m_shape.m_type == Shape::CIRCLE) - { - geom_node->SetAttribute("shape","CIRCLE"); - geom_node->SetDoubleAttribute("radius",m_shape.m_radius); - geom_node->RemoveAttribute("extent_x"); - geom_node->RemoveAttribute("extent_y"); - } - else - { - geom_node->SetAttribute("shape","RECT"); - geom_node->SetDoubleAttribute("extent_x",m_shape.m_extent.m_x); - geom_node->SetDoubleAttribute("extent_y",m_shape.m_extent.m_y); - geom_node->RemoveAttribute("radius"); - } + if (linkedNode != NULL) + { + // Only use geom_node if it was not deleted (can be deleted when linked). + if (m_shape.m_type == Shape::CIRCLE) + { + geom_node->SetAttribute("shape","CIRCLE"); + geom_node->SetDoubleAttribute("radius",m_shape.m_radius); + geom_node->RemoveAttribute("extent_x"); + geom_node->RemoveAttribute("extent_y"); + } + else + { + geom_node->SetAttribute("shape","RECT"); + geom_node->SetDoubleAttribute("extent_x",m_shape.m_extent.m_x); + geom_node->SetDoubleAttribute("extent_y",m_shape.m_extent.m_y); + geom_node->RemoveAttribute("radius"); + } + } } void FixedObjectData::operator=(const FixedObjectData& other)
--- a/src/gui/contenteditor/fixedobjecteditor.cpp Thu Apr 10 21:10:58 2014 +0300 +++ b/src/gui/contenteditor/fixedobjecteditor.cpp Thu Apr 10 21:32:12 2014 +0300 @@ -89,7 +89,7 @@ TiXmlNode* linkedNode = NULL; TiXmlElement * fixed_root = new TiXmlElement("Object"); linkedNode = m_fixed_object_xml.LinkEndChild(fixed_root); - if (fixed_root == NULL) + if (linkedNode == NULL) { // Failed to link the root item. return;