Merge pull request #87 from badgerman/master

DESCRIBE would crash if not given a description (crash).
This commit is contained in:
Enno Rehling 2014-12-20 22:43:58 +01:00
commit e04d002420
2 changed files with 37 additions and 3 deletions

View File

@ -1634,9 +1634,14 @@ int display_cmd(unit * u, struct order *ord)
const char *s2 = getstrtoken();
free(*s);
*s = _strdup(s2);
if (strlen(s2) >= DISPLAYSIZE) {
(*s)[DISPLAYSIZE] = 0;
if (s2) {
*s = _strdup(s2);
if (strlen(s2) >= DISPLAYSIZE) {
(*s)[DISPLAYSIZE] = 0;
}
}
else {
*s = 0;
}
}

View File

@ -198,6 +198,34 @@ static void test_enter_ship(CuTest * tc)
test_cleanup();
}
static void test_display_cmd(CuTest *tc) {
unit *u;
faction *f;
region *r;
order *ord;
test_cleanup();
r = test_create_region(0, 0, test_create_terrain("plain", LAND_REGION));
f = test_create_faction(0);
f->locale = get_or_create_locale("de");
assert(r && f);
test_translate_param(f->locale, P_UNIT, "EINHEIT");
u = test_create_unit(f, r);
assert(u);
ord = create_order(K_DISPLAY, f->locale, "EINHEIT Hodor");
CuAssertIntEquals(tc, 0, display_cmd(u, ord));
CuAssertStrEquals(tc, "Hodor", u->display);
free_order(ord);
ord = create_order(K_DISPLAY, f->locale, "EINHEIT");
CuAssertIntEquals(tc, 0, display_cmd(u, ord));
CuAssertPtrEquals(tc, NULL, u->display);
free_order(ord);
test_cleanup();
}
static void test_fishing_feeds_2_people(CuTest * tc)
{
const resource_type *rtype;
@ -620,5 +648,6 @@ CuSuite *get_laws_suite(void)
SUITE_ADD_TEST(suite, test_contact);
SUITE_ADD_TEST(suite, test_enter_building);
SUITE_ADD_TEST(suite, test_enter_ship);
SUITE_ADD_TEST(suite, test_display_cmd);
return suite;
}