diff --git a/src/give.test.c b/src/give.test.c index a5714f445..b79214040 100644 --- a/src/give.test.c +++ b/src/give.test.c @@ -296,6 +296,31 @@ static void test_give_denied_by_rules(CuTest * tc) { test_cleanup(); } +static void test_give_invalid_target(CuTest *tc) { + // bug https://bugs.eressea.de/view.php?id=1685 + struct give env; + order *ord; + struct locale * lang; + + test_cleanup(); + env.f1 = test_create_faction(0); + env.f2 = 0; + setup_give(&env); + + i_change(&env.src->items, env.itype, 10); + lang = get_or_create_locale("test"); + env.f1->locale = lang; + locale_setstring(lang, "KRAEUTER", "HERBS"); + init_locale(lang); + ord = create_order(K_GIVE, lang, "## HERBS"); + assert(ord); + + give_cmd(env.src, ord); + CuAssertIntEquals(tc, 10, i_get(env.src->items, env.itype)); + CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "feedback_unit_not_found")); + test_cleanup(); +} + CuSuite *get_give_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -315,5 +340,6 @@ CuSuite *get_give_suite(void) SUITE_ADD_TEST(suite, test_give_herbs); SUITE_ADD_TEST(suite, test_give_okay); SUITE_ADD_TEST(suite, test_give_denied_by_rules); + SUITE_ADD_TEST(suite, test_give_invalid_target); return suite; } diff --git a/src/kernel/config.c b/src/kernel/config.c index 573126137..a63fb092d 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -1025,6 +1025,16 @@ typedef struct param { char *data; } param; +void free_params(struct param **pp) { + while (*pp) { + param *p = *pp; + free(p->name); + free(p->data); + *pp = p->next; + free(p); + } +} + const char *get_param(const struct param *p, const char *key) { while (p != NULL) { diff --git a/src/kernel/config.h b/src/kernel/config.h index 056de8f84..2f71f7e01 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -277,6 +277,7 @@ extern "C" { int get_param_int(const struct param *p, const char *key, int def); int check_param(const struct param *p, const char *key, const char *searchvalue); float get_param_flt(const struct param *p, const char *key, float def); + void free_params(struct param **pp); bool ExpensiveMigrants(void); int NMRTimeout(void); diff --git a/src/tests.c b/src/tests.c index bcbd18c29..fe0e7bfcd 100644 --- a/src/tests.c +++ b/src/tests.c @@ -73,6 +73,7 @@ void test_cleanup(void) free_resources(); global.functions.maintenance = NULL; global.functions.wage = NULL; + free_params(&global.parameters); default_locale = 0; free_locales(); free_spells();