coverity scan does not understand get_or_create_equipment?

This commit is contained in:
Enno Rehling 2017-09-17 09:31:43 +02:00
parent 0d0fb49381
commit 8e0bdbe428
4 changed files with 25 additions and 13 deletions

View File

@ -214,10 +214,9 @@ equipment *get_equipment(const char *eqname)
return eq; return eq;
} }
equipment *get_or_create_equipment(const char *eqname) equipment *create_equipment(const char *eqname)
{ {
equipment *eq = get_equipment(eqname); equipment *eq;
if (!eq) {
size_t len; size_t len;
char data[64]; char data[64];
@ -227,6 +226,14 @@ equipment *get_or_create_equipment(const char *eqname)
len = cb_new_kv(eqname, strlen(eqname), &eq, sizeof(eq), data); len = cb_new_kv(eqname, strlen(eqname), &eq, sizeof(eq), data);
assert(len <= sizeof(data)); assert(len <= sizeof(data));
cb_insert(&cb_equipments, data, len); cb_insert(&cb_equipments, data, len);
return eq;
}
equipment *get_or_create_equipment(const char *eqname)
{
equipment *eq = get_equipment(eqname);
if (!eq) {
return create_equipment(eqname);
} }
return eq; return eq;
} }

View File

@ -57,6 +57,7 @@ extern "C" {
struct equipment *get_or_create_equipment(const char *eqname); struct equipment *get_or_create_equipment(const char *eqname);
struct equipment *get_equipment(const char *eqname); struct equipment *get_equipment(const char *eqname);
struct equipment *create_equipment(const char *eqname);
void equipment_setitem(struct equipment *eq, void equipment_setitem(struct equipment *eq,
const struct item_type *itype, const char *value); const struct item_type *itype, const char *value);

View File

@ -46,10 +46,10 @@ extern "C" {
int level; int level;
} msglevel; } msglevel;
extern struct message *msg_message(const char *name, const char *sig, ...); struct message *msg_message(const char *name, const char *sig, ...);
extern struct message *msg_feedback(const struct unit *, struct order *cmd, struct message *msg_feedback(const struct unit *, struct order *cmd,
const char *name, const char *sig, ...); const char *name, const char *sig, ...);
extern struct message *add_message(struct message_list **pm, struct message *add_message(struct message_list **pm,
struct message *m); struct message *m);
void addmessage(struct region *r, struct faction *f, const char *s, void addmessage(struct region *r, struct faction *f, const char *s,
msg_t mtype, int level); msg_t mtype, int level);

View File

@ -1069,9 +1069,13 @@ static int parse_equipment(xmlDocPtr doc)
xmlChar *propName = xmlGetProp(node, BAD_CAST "name"); xmlChar *propName = xmlGetProp(node, BAD_CAST "name");
if (propName != NULL) { if (propName != NULL) {
equipment *eq = get_or_create_equipment((const char *)propName); equipment *eq = get_equipment((const char *)propName);
xmlXPathObjectPtr xpathResult; xmlXPathObjectPtr xpathResult;
if (!eq) {
eq = create_equipment((const char *)propName);
}
xpath->node = node; xpath->node = node;
xpathResult = xmlXPathEvalExpression(BAD_CAST "callback", xpath); xpathResult = xmlXPathEvalExpression(BAD_CAST "callback", xpath);