diff --git a/src/magic.c b/src/magic.c index 8b8cf9c3d..517921212 100644 --- a/src/magic.c +++ b/src/magic.c @@ -2268,6 +2268,10 @@ void fix_fam_spells(unit *u) { sc_mage *dmage; unit *du = unit_create(0); + if (!is_familiar(u)) { + return; + } + u_setrace(du, u_race(u)); dmage = create_mage(du, M_GRAY); equip_familiar(du); diff --git a/src/magic.test.c b/src/magic.test.c index e70e026ca..ead8a6a8a 100644 --- a/src/magic.test.c +++ b/src/magic.test.c @@ -540,11 +540,19 @@ static void test_fix_fam_spells(CuTest *tc) { CuAssertPtrEquals(tc, NULL, unit_get_spellbook(u)); CuAssertTrue(tc, !u_hasspell(u, sp)); callbacks.equip_unit = equip_spell; + CuAssertTrue(tc, is_familiar(u)); fix_fam_spells(u); + CuAssertTrue(tc, is_familiar(u)); CuAssertPtrNotNull(tc, unit_get_spellbook(u)); CuAssertTrue(tc, u_hasspell(u, sp)); /* u is a migrant, and does not get equipped: */ + u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0)); + u_setrace(u, rc); + CuAssertTrue(tc, !is_familiar(u)); + fix_fam_spells(u); + CuAssertTrue(tc, !is_familiar(u)); + CuAssertPtrEquals(tc, NULL, unit_get_spellbook(u)); test_teardown(); }