do not crash when starting equipment isn't defined in the xml file (it may be in the lua file, after all).

This commit is contained in:
Enno Rehling 2005-06-04 15:18:18 +00:00
parent 5c9e9f7b9a
commit ea321bbc59
2 changed files with 19 additions and 19 deletions

View File

@ -79,8 +79,6 @@ typedef struct donation {
int amount; int amount;
} donation; } donation;
static donation *donations = 0;
typedef struct request { typedef struct request {
struct request * next; struct request * next;
struct unit *unit; struct unit *unit;

View File

@ -841,30 +841,32 @@ parse_equipment(xmlDocPtr doc)
{ {
xmlXPathContextPtr xpath = xmlXPathNewContext(doc); xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
xmlXPathObjectPtr items; xmlXPathObjectPtr items;
xmlNodeSetPtr nodes; xmlNodeSetPtr nsetItems;
int i; int i;
/* reading eressea/races/race */ /* reading eressea/races/race */
items = xmlXPathEvalExpression(BAD_CAST "/eressea/equipment/item", xpath); items = xmlXPathEvalExpression(BAD_CAST "/eressea/equipment/item", xpath);
nodes = items->nodesetval; nsetItems = items->nodesetval;
for (i=0;i!=nodes->nodeNr;++i) { if (nsetItems!=NULL) {
xmlNodePtr node = nodes->nodeTab[i]; for (i=0;i!=nsetItems->nodeNr;++i) {
xmlChar * property; xmlNodePtr node = nsetItems->nodeTab[i];
const struct item_type * itype; xmlChar * property;
const struct item_type * itype;
property = xmlGetProp(node, BAD_CAST "name"); property = xmlGetProp(node, BAD_CAST "name");
assert(property!=NULL); assert(property!=NULL);
itype = it_find((const char*)property); itype = it_find((const char*)property);
xmlFree(property); xmlFree(property);
if (itype!=NULL) { if (itype!=NULL) {
int num = 0; int num = 0;
property = xmlGetProp(node, BAD_CAST "amount"); property = xmlGetProp(node, BAD_CAST "amount");
if (property!=NULL) { if (property!=NULL) {
num = atoi((const char*)property); num = atoi((const char*)property);
xmlFree(property); xmlFree(property);
}
add_equipment(itype, num);
} }
add_equipment(itype, num);
} }
} }
xmlXPathFreeObject(items); xmlXPathFreeObject(items);