From 440df3425dcc2376755d622ad6fd965eb25a25c2 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 15 Mar 2015 20:57:46 -0400 Subject: Fixed the empty XML bug AGAIN --- src/map.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/map.cpp b/src/map.cpp index 36baab6..29f22ec 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -43,7 +43,11 @@ Map::Map(const std::string name) if (!xmlStrcmp(node->name, (const xmlChar*) "name")) { xmlChar* key = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); - title = (char*) key; + if (key != 0) + { + title = (char*) key; + } + xmlFree(key); } else if (!xmlStrcmp(node->name, (const xmlChar*) "environment")) { @@ -67,7 +71,11 @@ Map::Map(const std::string name) if (!xmlStrcmp(entityDataNode->name, (const xmlChar*) "entity-type")) { xmlChar* key = xmlNodeListGetString(doc, entityDataNode->xmlChildrenNode, 1); - data.name = std::string((char*) key); + if (key != 0) + { + data.name = (char*) key; + } + xmlFree(key); } else if (!xmlStrcmp(entityDataNode->name, (const xmlChar*) "entity-position")) { @@ -83,23 +91,21 @@ Map::Map(const std::string name) } else if (!xmlStrcmp(node->name, (const xmlChar*) "leftmap")) { xmlChar* key = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); - std::string mapname = (char*) key; - xmlFree(key); - - if (mapname.length() > 0) + if (key != 0) { - leftMap = &Map::getNamedMap(mapname); + leftMap = &Map::getNamedMap((char*) key); } + + xmlFree(key); } else if (!xmlStrcmp(node->name, (const xmlChar*) "rightmap")) { xmlChar* key = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); - std::string mapname = (char*) key; - xmlFree(key); - - if (mapname.length() > 0) + if (key != 0) { - rightMap = &Map::getNamedMap(mapname); + rightMap = &Map::getNamedMap((char*) key); } + + xmlFree(key); } } -- cgit 1.4.1