fix bug 2261: bit manipulation error in STEALTH FACTION.

https://bugs.eressea.de/view.php?id=2261
This commit is contained in:
Enno Rehling 2016-12-03 23:38:53 +01:00
parent cd2842ef38
commit afac66e213
2 changed files with 24 additions and 3 deletions

View File

@ -295,11 +295,11 @@ int setstealth_cmd(unit * u, struct order *ord)
s = gettoken(token, sizeof(token)); s = gettoken(token, sizeof(token));
if (rule_stealth_anon()) { if (rule_stealth_anon()) {
if (!s || *s == 0) { if (!s || *s == 0) {
fset(u, UFL_ANON_FACTION); u->flags |= UFL_ANON_FACTION;
break; break;
} }
else if (findparam(s, u->faction->locale) == P_NOT) { else if (findparam(s, u->faction->locale) == P_NOT) {
u->flags |= ~UFL_ANON_FACTION; u->flags &= ~UFL_ANON_FACTION;
break; break;
} }
} }
@ -416,7 +416,7 @@ static void sink_ship(region * r, ship * sh, unit * saboteur)
/* slight optimization to avoid dereferencing u->faction each time */ /* slight optimization to avoid dereferencing u->faction each time */
if (f != u->faction) { if (f != u->faction) {
f = u->faction; f = u->faction;
f->flags |= ~FFL_SELECT; f->flags &= ~FFL_SELECT;
} }
} }

View File

@ -146,6 +146,26 @@ static void test_sabotage_other_fail(CuTest *tc) {
test_cleanup(); test_cleanup();
} }
static void test_setstealth_cmd(CuTest *tc) {
unit *u;
const struct locale *lang;
test_setup();
u = test_create_unit(test_create_faction(0), test_create_region(0,0,0));
lang = u->faction->locale;
u->flags = UFL_ANON_FACTION|UFL_SIEGE;
u->thisorder = create_order(K_SETSTEALTH, lang, "%s %s",
LOC(lang, parameters[P_FACTION]),
LOC(lang, parameters[P_NOT]));
setstealth_cmd(u, u->thisorder);
CuAssertIntEquals(tc, UFL_SIEGE, u->flags);
free_order(u->thisorder);
u->thisorder = create_order(K_SETSTEALTH, lang, "%s",
LOC(lang, parameters[P_FACTION]));
setstealth_cmd(u, u->thisorder);
CuAssertIntEquals(tc, UFL_SIEGE|UFL_ANON_FACTION, u->flags);
test_cleanup();
}
static void test_sabotage_other_success(CuTest *tc) { static void test_sabotage_other_success(CuTest *tc) {
unit *u, *u2; unit *u, *u2;
@ -178,6 +198,7 @@ CuSuite *get_spy_suite(void)
SUITE_ADD_TEST(suite, test_simple_spy_message); SUITE_ADD_TEST(suite, test_simple_spy_message);
SUITE_ADD_TEST(suite, test_all_spy_message); SUITE_ADD_TEST(suite, test_all_spy_message);
SUITE_ADD_TEST(suite, test_sabotage_self); SUITE_ADD_TEST(suite, test_sabotage_self);
SUITE_ADD_TEST(suite, test_setstealth_cmd);
SUITE_ADD_TEST(suite, test_sabotage_other_fail); SUITE_ADD_TEST(suite, test_sabotage_other_fail);
SUITE_ADD_TEST(suite, test_sabotage_other_success); SUITE_ADD_TEST(suite, test_sabotage_other_success);
return suite; return suite;