summaryrefslogtreecommitdiff
path: root/ContentBuildingReader.cpp
diff options
context:
space:
mode:
authorPetr Mrázek2012-02-19 14:57:25 +0100
committerPetr Mrázek2012-02-19 14:57:25 +0100
commit952e5d78ab6160be0e13446b0beabef301542848 (patch)
tree3319ce57d08b9f9c859150f257f9a64b91771f38 /ContentBuildingReader.cpp
parentc1005ebf6784fa2bbe4b4cb9e1403329e13388ce (diff)
downloadstonesense-952e5d78ab6160be0e13446b0beabef301542848.tar.gz
stonesense-952e5d78ab6160be0e13446b0beabef301542848.tar.bz2
stonesense-952e5d78ab6160be0e13446b0beabef301542848.tar.xz
Fix stupid bugs and segfaults comming from C strings.
Diffstat (limited to 'ContentBuildingReader.cpp')
-rw-r--r--ContentBuildingReader.cpp70
1 files changed, 61 insertions, 9 deletions
diff --git a/ContentBuildingReader.cpp b/ContentBuildingReader.cpp
index 10dc0bb..78a5d8a 100644
--- a/ContentBuildingReader.cpp
+++ b/ContentBuildingReader.cpp
@@ -301,17 +301,21 @@ bool addSingleBuildingConfig( TiXmlElement* elemRoot, vector<BuildingConfigurat
}
building_type::building_type main_type = (building_type::building_type) INVALID_INDEX;
int subtype = INVALID_INDEX;
-
+ string game_type_s;
FOR_ENUM_ITEMS(building_type,i)
{
- if (strGameID == ENUM_KEY_STR(building_type,i))
+ game_type_s = strGameID;
+ if (game_type_s == ENUM_KEY_STR(building_type,i))
{
main_type = i;
break;
}
}
if(main_type == (building_type::building_type) INVALID_INDEX)
+ {
+ contentError("<building> unknown game_type value",elemRoot);
return false;
+ }
// get subtype string, if available
string sub;
@@ -325,74 +329,114 @@ bool addSingleBuildingConfig( TiXmlElement* elemRoot, vector<BuildingConfigurat
{
case building_type::Furnace:
{
+ if(!strGameSub)
+ {
+ contentError("<building> missing game_subtype attribute",elemRoot);
+ return false;
+ }
FOR_ENUM_ITEMS(furnace_type,i)
{
- if (strGameSub == ENUM_KEY_STR(furnace_type,i))
+ if (sub == ENUM_KEY_STR(furnace_type,i))
{
subtype = i;
break;
}
}
if(subtype == INVALID_INDEX)
+ {
+ contentError("<building> unknown game_subtype value",elemRoot);
return false;
+ }
if(subtype == furnace_type::Custom)
needs_custom = true;
break;
}
case building_type::Construction:
{
+ if(!strGameSub)
+ {
+ contentError("<building> missing game_subtype attribute",elemRoot);
+ return false;
+ }
FOR_ENUM_ITEMS(construction_type,i)
{
- if (strGameSub == ENUM_KEY_STR(construction_type,i))
+ if (sub == ENUM_KEY_STR(construction_type,i))
{
subtype = i;
break;
}
}
if(subtype == INVALID_INDEX)
+ {
+ contentError("<building> unknown game_subtype value",elemRoot);
return false;
+ }
break;
}
case building_type::SiegeEngine:
{
+ if(!strGameSub)
+ {
+ contentError("<building> missing game_subtype attribute",elemRoot);
+ return false;
+ }
FOR_ENUM_ITEMS(siegeengine_type,i)
{
- if (strGameSub == ENUM_KEY_STR(siegeengine_type,i))
+ if (sub == ENUM_KEY_STR(siegeengine_type,i))
{
subtype = i;
break;
}
}
if(subtype == INVALID_INDEX)
+ {
+ contentError("<building> unknown game_subtype value",elemRoot);
return false;
+ }
break;
}
case building_type::Shop:
{
+ if(!strGameSub)
+ {
+ contentError("<building> missing game_subtype attribute",elemRoot);
+ return false;
+ }
FOR_ENUM_ITEMS(shop_type,i)
{
- if (strGameSub == ENUM_KEY_STR(shop_type,i))
+ if (sub == ENUM_KEY_STR(shop_type,i))
{
subtype = i;
break;
}
}
if(subtype == INVALID_INDEX)
+ {
+ contentError("<building> unknown game_subtype value",elemRoot);
return false;
+ }
break;
}
case building_type::Workshop:
{
+ if(!strGameSub)
+ {
+ contentError("<building> missing game_subtype attribute",elemRoot);
+ return false;
+ }
FOR_ENUM_ITEMS(workshop_type,i)
{
- if (strGameSub == ENUM_KEY_STR(workshop_type,i))
+ if (sub == ENUM_KEY_STR(workshop_type,i))
{
subtype = i;
break;
}
}
if(subtype == INVALID_INDEX)
+ {
+ contentError("<building> unknown game_subtype value",elemRoot);
return false;
+ }
if(subtype == workshop_type::Custom)
needs_custom = true;
break;
@@ -403,16 +447,24 @@ bool addSingleBuildingConfig( TiXmlElement* elemRoot, vector<BuildingConfigurat
break;
}
}
+ string custom;
// needs custom building spec, doesn't have a string... FAIL
if (needs_custom && !strGameCustom)
+ {
+ contentError("<building> game_custom attribute is required, but missng.",elemRoot);
return false;
-
- BuildingConfiguration building(strName, main_type, subtype, string(strGameCustom) );
+ }
+ else if (strGameCustom)
+ {
+ custom = strGameCustom;
+ }
+ BuildingConfiguration building(strName, main_type, subtype, custom );
RootBlock* spriteroot = new RootBlock();
building.sprites = spriteroot;
if (!parseSpriteNode(spriteroot,elemRoot))
{
delete(spriteroot);
+ contentError("<building> Failed while parsing sprite node",elemRoot);
return false;
}