diff --git a/src/common/kernel/battle.c b/src/common/kernel/battle.c index 022a79abc..757ba936e 100644 --- a/src/common/kernel/battle.c +++ b/src/common/kernel/battle.c @@ -1872,7 +1872,6 @@ do_extra_spell(troop at, const att *a) { const spell *sp = a->data.sp; fighter *fi = at.fighter; - unit *au = fi->unit; double power; power = sp->level * MagicPower(); diff --git a/src/common/kernel/plane.c b/src/common/kernel/plane.c index c2ec54337..770e90558 100644 --- a/src/common/kernel/plane.c +++ b/src/common/kernel/plane.c @@ -93,7 +93,7 @@ getplanebyname(const char * name) plane *p; for (p=planes; p; p=p->next) - if (!strcmp(p->name, name)) + if (p->name && !strcmp(p->name, name)) return p; return NULL; } diff --git a/src/common/kernel/race.c b/src/common/kernel/race.c index dce50a583..a736e59b7 100644 --- a/src/common/kernel/race.c +++ b/src/common/kernel/race.c @@ -204,7 +204,7 @@ r_insectstalled(const region * r) const char * rc_name(const race * rc, int n) { - return mkname("race", rc->_name[n]); + return rc?mkname("race", rc->_name[n]):NULL; } const char * diff --git a/src/common/kernel/reports.c b/src/common/kernel/reports.c index 073745998..718cb134f 100644 --- a/src/common/kernel/reports.c +++ b/src/common/kernel/reports.c @@ -303,7 +303,7 @@ report_race(const struct unit * u, const char ** name, const char ** illusion) { if (illusion) { const race * irace = u_irace(u); - if (irace!=u->race) { + if (irace && irace!=u->race) { *illusion = irace->_name[0]; } else { diff --git a/src/common/kernel/save.c b/src/common/kernel/save.c index c450d00c3..b8793e57f 100644 --- a/src/common/kernel/save.c +++ b/src/common/kernel/save.c @@ -853,7 +853,7 @@ write_unit(struct storage * store, const unit * u) store->w_int(store, u->number); store->w_int(store, u->age); store->w_tok(store, u->race->_name[0]); - store->w_tok(store, irace!=u->race?u->irace->_name[0]:""); + store->w_tok(store, (irace && irace!=u->race)?irace->_name[0]:""); write_building_reference(u->building, store); write_ship_reference(u->ship, store); store->w_int(store, u->status); diff --git a/src/common/kernel/unit.c b/src/common/kernel/unit.c index 91e6533fc..66c3fe3b3 100644 --- a/src/common/kernel/unit.c +++ b/src/common/kernel/unit.c @@ -1733,8 +1733,8 @@ scale_number (unit * u, int n) const struct race * u_irace(const struct unit * u) { - if (skill_enabled[SK_STEALTH]) { + if (u->irace && skill_enabled[SK_STEALTH]) { return u->irace; } return u->race; -} \ No newline at end of file +} diff --git a/src/eressea/tolua/bind_building.c b/src/eressea/tolua/bind_building.c index 3f3666925..8abc8a75c 100644 --- a/src/eressea/tolua/bind_building.c +++ b/src/eressea/tolua/bind_building.c @@ -164,9 +164,11 @@ tolua_building_create(lua_State* L) const char * bname = tolua_tostring(L, 2, 0); if (bname) { const building_type * btype = bt_find(bname); - building * b = new_building(btype, r, NULL); - tolua_pushusertype(L, (void*)b, TOLUA_CAST "building"); - return 1; + if (btype) { + building * b = new_building(btype, r, NULL); + tolua_pushusertype(L, (void*)b, TOLUA_CAST "building"); + return 1; + } } return 0; } diff --git a/src/eressea/tolua/bind_unit.c b/src/eressea/tolua/bind_unit.c index 616b6a21f..562b2d2e3 100644 --- a/src/eressea/tolua/bind_unit.c +++ b/src/eressea/tolua/bind_unit.c @@ -664,7 +664,7 @@ static void unit_setship(unit * u, ship * s) { leave(u, true); - if (u->region!=s->region) { + if (s && u->region!=s->region) { move_unit(u, s->region, NULL); } u->ship = s; diff --git a/src/scripts/config-test.lua b/src/scripts/config-test.lua new file mode 100644 index 000000000..67bb64082 --- /dev/null +++ b/src/scripts/config-test.lua @@ -0,0 +1 @@ +maxnmrs = 500 diff --git a/src/scripts/tests.lua b/src/scripts/tests.lua index b97972169..d73d14906 100644 --- a/src/scripts/tests.lua +++ b/src/scripts/tests.lua @@ -625,12 +625,13 @@ function test_leave() b2.size = 10 local u = unit.create(f, r, 1) u.building = b1 + assert(u.building~=nil) u:add_item("money", u.number * 100) u:clear_orders() u:add_order("BETRETE BURG " .. itoa36(b2.id)) update_owners() process_orders() - assert(u.building==b1) + assert(u.building.id==b1.id) -- region owners may not leave end function test_mallorn() @@ -787,7 +788,7 @@ mytests = { ["owners"] = test_owners } fail = 0 -for k, v in pairs(mytests) do +for k, v in pairs(tests) do local status, err = pcall(v) if not status then fail = fail + 1