fix null pointer access, bug2169

This commit is contained in:
Steffen Mecke 2015-11-29 21:06:35 +01:00
parent b1ac0fe0b1
commit eae87bc7f1
2 changed files with 19 additions and 1 deletions

View File

@ -808,7 +808,7 @@ static void drifting_ships(region * r)
/* Kapitän bestimmen */ /* Kapitän bestimmen */
captain = ship_owner(sh); captain = ship_owner(sh);
if (effskill(captain, SK_SAILING, r) < sh->type->cptskill) if (captain && effskill(captain, SK_SAILING, r) < sh->type->cptskill)
captain = NULL; captain = NULL;
/* Kapitän da? Beschädigt? Genügend Matrosen? /* Kapitän da? Beschädigt? Genügend Matrosen?

View File

@ -324,6 +324,23 @@ static void test_ship_no_overload(CuTest *tc) {
test_cleanup(); test_cleanup();
} }
static void test_ship_empty(CuTest *tc) {
struct drift_fixture fix;
test_cleanup();
setup_drift(&fix);
fix.u->ship = NULL;
ship_update_owner(fix.sh);
movement();
CuAssertPtrEquals(tc, fix.sh->region, findregion(0, 0));
CuAssertIntEquals(tc, 2, ship_damage_percent(fix.sh));
CuAssertPtrEquals(tc, 0, test_find_messagetype(fix.f->msgs, "ship_drift"));
test_cleanup();
}
static void test_ship_normal_overload(CuTest *tc) { static void test_ship_normal_overload(CuTest *tc) {
struct drift_fixture fix; struct drift_fixture fix;
@ -505,6 +522,7 @@ CuSuite *get_move_suite(void)
SUITE_ADD_TEST(suite, test_ship_trails); SUITE_ADD_TEST(suite, test_ship_trails);
SUITE_ADD_TEST(suite, test_age_trails); SUITE_ADD_TEST(suite, test_age_trails);
SUITE_ADD_TEST(suite, test_ship_no_overload); SUITE_ADD_TEST(suite, test_ship_no_overload);
SUITE_ADD_TEST(suite, test_ship_empty);
SUITE_ADD_TEST(suite, test_ship_normal_overload); SUITE_ADD_TEST(suite, test_ship_normal_overload);
SUITE_ADD_TEST(suite, test_ship_no_real_overload); SUITE_ADD_TEST(suite, test_ship_no_real_overload);
SUITE_ADD_TEST(suite, test_ship_big_overload); SUITE_ADD_TEST(suite, test_ship_big_overload);