From 2103c1725ecaa7e6b726a1deea2156d2aad278bd Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 26 May 2012 11:29:27 -0700 Subject: [PATCH] Fix accidental parsing of empty strings (Bug 1917) --- src/gamecode/laws.c | 52 +++++++++++++++++++++++---------------------- src/kernel/config.c | 2 +- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/gamecode/laws.c b/src/gamecode/laws.c index 317def2ca..660fc1580 100644 --- a/src/gamecode/laws.c +++ b/src/gamecode/laws.c @@ -2445,34 +2445,36 @@ static void reshow(unit * u, struct order *ord, const char *s, param_t p) cmistake(u, ord, 285, MSG_EVENT); break; case NOPARAM: - /* check if it's an item */ - itype = finditemtype(s, u->faction->locale); - if (itype != NULL) { - ptype = resource2potion(item2resource(itype)); - if (ptype != NULL) { - if (display_potion(u->faction, u, ptype)) - break; - } else { - if (display_item(u->faction, u, itype)) - break; + if (s) { + /* check if it's an item */ + itype = finditemtype(s, u->faction->locale); + if (itype != NULL) { + ptype = resource2potion(item2resource(itype)); + if (ptype != NULL) { + if (display_potion(u->faction, u, ptype)) + break; + } else { + if (display_item(u->faction, u, itype)) + break; + } } - } - /* try for a spell */ - sp = unit_getspell(u, s, u->faction->locale); - if (sp) { - attrib *a = a_find(u->faction->attribs, &at_seenspell); - while (a != NULL && a->type == &at_seenspell && a->data.v != sp) { - a = a->next; + /* try for a spell */ + sp = unit_getspell(u, s, u->faction->locale); + if (sp) { + attrib *a = a_find(u->faction->attribs, &at_seenspell); + while (a != NULL && a->type == &at_seenspell && a->data.v != sp) { + a = a->next; + } + if (a != NULL) { + a_remove(&u->faction->attribs, a); + } + break; } - if (a != NULL) { - a_remove(&u->faction->attribs, a); + /* last, check if it's a race. */ + rc = findrace(s, u->faction->locale); + if (rc != NULL && display_race(u->faction, u, rc)) { + break; } - break; - } - /* last, check if it's a race. */ - rc = findrace(s, u->faction->locale); - if (rc != NULL && display_race(u->faction, u, rc)) { - break; } cmistake(u, ord, 21, MSG_EVENT); break; diff --git a/src/kernel/config.c b/src/kernel/config.c index 7033e4ba8..114e5cafb 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -1397,7 +1397,7 @@ param_t findparam(const char *s, const struct locale * lang) char buffer[64]; char * str = transliterate(buffer, sizeof(buffer)-sizeof(int), s); - if (str) { + if (str && *str) { int i; const void * match; void **tokens = get_translations(lang, UT_PARAMS);