forked from github/server
fix crash in mail_cmd when order is missing a message
This commit is contained in:
parent
37a8081c9b
commit
99c385412a
|
@ -1,3 +1,3 @@
|
|||
#define VERSION_MAJOR 3
|
||||
#define VERSION_MINOR 6
|
||||
#define VERSION_BUILD 4
|
||||
#define VERSION_BUILD 5
|
||||
|
|
|
@ -2027,7 +2027,7 @@ int mail_cmd(unit * u, struct order *ord)
|
|||
}
|
||||
|
||||
s = getstrtoken();
|
||||
if (!s[0]) {
|
||||
if (!s || !s[0]) {
|
||||
cmistake(u, ord, 30, MSG_MESSAGE);
|
||||
break;
|
||||
}
|
||||
|
@ -2050,7 +2050,7 @@ int mail_cmd(unit * u, struct order *ord)
|
|||
}
|
||||
|
||||
s = getstrtoken();
|
||||
if (!s[0]) {
|
||||
if (!s || !s[0]) {
|
||||
cmistake(u, ord, 30, MSG_MESSAGE);
|
||||
break;
|
||||
}
|
||||
|
@ -2082,7 +2082,7 @@ int mail_cmd(unit * u, struct order *ord)
|
|||
|
||||
s = getstrtoken();
|
||||
|
||||
if (!s[0]) {
|
||||
if (!s || !s[0]) {
|
||||
cmistake(u, ord, 30, MSG_MESSAGE);
|
||||
break;
|
||||
}
|
||||
|
@ -2111,7 +2111,7 @@ int mail_cmd(unit * u, struct order *ord)
|
|||
|
||||
s = getstrtoken();
|
||||
|
||||
if (!s[0]) {
|
||||
if (!s || !s[0]) {
|
||||
cmistake(u, ord, 30, MSG_MESSAGE);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -970,7 +970,7 @@ static void test_ally_cmd(CuTest *tc) {
|
|||
test_cleanup();
|
||||
}
|
||||
|
||||
void test_nmr_warnings(CuTest *tc) {
|
||||
static void test_nmr_warnings(CuTest *tc) {
|
||||
faction *f1, *f2;
|
||||
test_cleanup();
|
||||
set_param(&global.parameters, "nmr.timeout", "3");
|
||||
|
@ -989,6 +989,43 @@ void test_nmr_warnings(CuTest *tc) {
|
|||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_mail_cmd(CuTest *tc) {
|
||||
unit *u;
|
||||
order *ord;
|
||||
faction *f;
|
||||
struct locale *lang;
|
||||
|
||||
test_cleanup();
|
||||
f = test_create_faction(0);
|
||||
f->locale = lang = get_or_create_locale("de");
|
||||
locale_setstring(lang, parameters[P_UNIT], "EINHEIT");
|
||||
init_parameters(lang);
|
||||
u = test_create_unit(f, test_create_region(0, 0, 0));
|
||||
ord = create_order(K_MAIL, u->faction->locale, "EINHEIT %s 'Hodor!'", itoa36(u->no));
|
||||
mail_cmd(u, ord);
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "unitmessage"));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_mail_cmd_no_msg(CuTest *tc) {
|
||||
unit *u;
|
||||
order *ord;
|
||||
faction *f;
|
||||
struct locale *lang;
|
||||
|
||||
test_cleanup();
|
||||
f = test_create_faction(0);
|
||||
f->locale = lang = get_or_create_locale("de");
|
||||
locale_setstring(lang, parameters[P_UNIT], "EINHEIT");
|
||||
init_parameters(lang);
|
||||
u = test_create_unit(f, test_create_region(0, 0, 0));
|
||||
ord = create_order(K_MAIL, u->faction->locale, "EINHEIT %s", itoa36(u->no));
|
||||
mail_cmd(u, ord);
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "unitmessage"));
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error30"));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
CuSuite *get_laws_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
|
@ -1033,6 +1070,8 @@ CuSuite *get_laws_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_force_leave_ships);
|
||||
SUITE_ADD_TEST(suite, test_force_leave_ships_on_ocean);
|
||||
SUITE_ADD_TEST(suite, test_peasant_luck_effect);
|
||||
SUITE_ADD_TEST(suite, test_mail_cmd);
|
||||
SUITE_ADD_TEST(suite, test_mail_cmd_no_msg);
|
||||
(void)test_luck_message; /* disabled, breaks on travis */
|
||||
|
||||
return suite;
|
||||
|
|
Loading…
Reference in New Issue