summaryrefslogtreecommitdiff
path: root/src/resources/mapreader.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-02-10 20:05:08 +0200
committerAndrei Karas <akaras@inbox.ru>2011-02-10 20:05:08 +0200
commit19b15c91bf8f179ff8468e42eaa4eaac8fc22708 (patch)
tree357d6378f0190ffd6751154d2ea0dd7470774125 /src/resources/mapreader.cpp
parenta12172bc3f8e291f464678c92d5ebf566d4cad2c (diff)
downloadplus-19b15c91bf8f179ff8468e42eaa4eaac8fc22708.tar.gz
plus-19b15c91bf8f179ff8468e42eaa4eaac8fc22708.tar.bz2
plus-19b15c91bf8f179ff8468e42eaa4eaac8fc22708.tar.xz
plus-19b15c91bf8f179ff8468e42eaa4eaac8fc22708.zip
Add checks to mapreader.
Diffstat (limited to 'src/resources/mapreader.cpp')
-rw-r--r--src/resources/mapreader.cpp57
1 files changed, 8 insertions, 49 deletions
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index c3a854c92..bf29aaa6e 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -455,6 +455,9 @@ void MapReader::readLayer(xmlNodePtr node, Map *map)
(const char*)dataChild->content) + 1);
unsigned char *charData = new unsigned char[len + 1];
const char *charStart = (const char*) xmlNodeGetContent(dataChild);
+ if (!charStart)
+ return;
+
unsigned char *charIndex = charData;
while (*charStart)
@@ -528,6 +531,9 @@ void MapReader::readLayer(xmlNodePtr node, Map *map)
continue;
const char *data = (const char*) xmlNodeGetContent(dataChild);
+ if (!data)
+ return;
+
std::string csv(data);
size_t pos = 0;
@@ -536,6 +542,8 @@ void MapReader::readLayer(xmlNodePtr node, Map *map)
while (oldPos != csv.npos)
{
pos = csv.find_first_of(",", oldPos);
+ if (pos == csv.npos)
+ return;
const int gid = atoi(csv.substr(oldPos, pos - oldPos).c_str());
@@ -584,55 +592,6 @@ void MapReader::readLayer(xmlNodePtr node, Map *map)
break;
}
-/*
- if (!layer)
- return;
-
- for (int y = 0; y < layer->getHeight(); y ++)
- {
- for (int x = 0 ; x < layer->getWidth() ; x ++)
- {
- int width;
- int c = layer->getTileDrawWidth(x, y, layer->getWidth(), width);
- layer->setTileInfo(x, y, width, c);
- }
- }
-*/
-
-/*
- Image *img1 = 0;
- for (int y = 0; y < layer->getHeight(); y ++)
- {
- int skipWidth = 0;
- int skipCount = 0;
- img1 = layer->getTile(0, y);
- layer->setTileInfo(layer->getWidth() - 1, y, skipWidth, skipCount);
- for (int x = layer->getWidth() - 1 ; x > 0 ; x --)
- {
- Image *img = layer->getTile(x, y);
- if (img)
- {
- if (img != img1)
- { // different tile
- skipWidth = 0;
- skipCount = 0;
- }
- else
- { // same tile
- skipWidth += img1->getWidth();
- skipCount ++;
- }
- }
- else
- {
- skipWidth = 0;
- skipCount = 0;
- }
- layer->setTileInfo(x, y, skipWidth, skipCount);
- img1 = img;
- }
- }
-*/
}
Tileset *MapReader::readTileset(xmlNodePtr node, const std::string &path,