fix renumber parser crash

This commit is contained in:
Enno Rehling 2018-11-25 09:21:37 +01:00 committed by Enno Rehling
parent 8855574938
commit 4c58127ce1
2 changed files with 8 additions and 3 deletions

View file

@ -167,7 +167,7 @@ int renumber_cmd(unit * u, order * ord)
break;
}
s = gettoken(token, sizeof(token));
if (*s == 0) {
if (s == NULL || *s == 0) {
i = newcontainerid();
}
else {

View file

@ -101,7 +101,12 @@ static void test_renumber_building(CuTest *tc) {
no = u->building->no;
uno = (no > 1) ? no - 1 : no + 1;
lang = u->faction->locale;
u->thisorder = create_order(K_NUMBER, lang, "%s %s", LOC(lang, parameters[P_BUILDING]), itoa36(uno));
u->thisorder = create_order(K_NUMBER, lang, LOC(lang, parameters[P_BUILDING]));
renumber_cmd(u, u->thisorder);
CuAssertTrue(tc, no != u->building->no);
free_order(u->thisorder);
u->thisorder = create_order(K_NUMBER, lang, "%s %i", LOC(lang, parameters[P_BUILDING]), uno);
renumber_cmd(u, u->thisorder);
CuAssertIntEquals(tc, uno, u->building->no);
test_teardown();
@ -120,7 +125,7 @@ static void test_renumber_building_duplicate(CuTest *tc) {
u->building = test_create_building(u->region, NULL);
no = u->building->no;
lang = f->locale;
u->thisorder = create_order(K_NUMBER, lang, "%s %s", LOC(lang, parameters[P_BUILDING]), itoa36(uno));
u->thisorder = create_order(K_NUMBER, lang, "%s %i", LOC(lang, parameters[P_BUILDING]), uno);
renumber_cmd(u, u->thisorder);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error115"));
CuAssertIntEquals(tc, no, u->building->no);