let's try something: exparse handlers should not allocate

This commit is contained in:
Enno Rehling 2021-03-13 14:39:20 +01:00
parent c5b8839634
commit e6e5e75c4c
1 changed files with 10 additions and 8 deletions

View File

@ -752,10 +752,8 @@ static void handle_modifier(parseinfo *pi, const XML_Char *el, const XML_Char **
} }
} }
static construction *parse_construction(parseinfo *pi, const XML_Char *el, const XML_Char **attr) { void parse_construction(construction *con, parseinfo *pi, const XML_Char *el, const XML_Char **attr) {
int i; int i;
construction *con = (construction *)calloc(1, sizeof(construction));
if (!con) abort();
con->maxsize = -1; con->maxsize = -1;
con->minskill = -1; con->minskill = -1;
con->reqsize = 1; con->reqsize = 1;
@ -781,7 +779,6 @@ static construction *parse_construction(parseinfo *pi, const XML_Char *el, const
} }
} }
nreqs = 0; nreqs = 0;
return con;
} }
static void start_resources(parseinfo *pi, const XML_Char *el, const XML_Char **attr) { static void start_resources(parseinfo *pi, const XML_Char *el, const XML_Char **attr) {
@ -831,7 +828,9 @@ static void start_resources(parseinfo *pi, const XML_Char *el, const XML_Char **
else if (rtype->itype) { else if (rtype->itype) {
item_type *itype = rtype->itype; item_type *itype = rtype->itype;
if (xml_strequal(el, "construction")) { if (xml_strequal(el, "construction")) {
itype->construction = parse_construction(pi, el, attr); itype->construction = calloc(1, sizeof(construction));
if (!itype->construction) abort();
parse_construction(itype->construction, pi, el, attr);
} }
else if (xml_strequal(el, "requirement")) { else if (xml_strequal(el, "requirement")) {
assert(itype->construction); assert(itype->construction);
@ -975,8 +974,9 @@ static void start_ships(parseinfo *pi, const XML_Char *el, const XML_Char **attr
handle_requirement(pi, el, attr); handle_requirement(pi, el, attr);
} }
else if (xml_strequal(el, "construction")) { else if (xml_strequal(el, "construction")) {
assert(!stype->construction); stype->construction = calloc(1, sizeof(construction));
stype->construction = parse_construction(pi, el, attr); if (!stype->construction) abort();
parse_construction(stype->construction, pi, el, attr);
} }
else if (xml_strequal(el, "coast")) { else if (xml_strequal(el, "coast")) {
handle_coast(pi, el, attr); handle_coast(pi, el, attr);
@ -1283,7 +1283,9 @@ static void start_buildings(parseinfo *pi, const XML_Char *el, const XML_Char **
assert(stage == NULL); assert(stage == NULL);
stage = (building_stage *)calloc(1, sizeof(building_stage)); stage = (building_stage *)calloc(1, sizeof(building_stage));
if (!stage) abort(); if (!stage) abort();
stage->construction = parse_construction(pi, el, attr); stage->construction = calloc(1, sizeof(construction));
if (!stage->construction) abort();
parse_construction(stage->construction, pi, el, attr);
} }
else if (xml_strequal(el, "maintenance")) { else if (xml_strequal(el, "maintenance")) {
assert(!btype->maintenance); assert(!btype->maintenance);