mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-24 15:59:31 +00:00
Fix unit tostring conversion causing a crash if the unit is invalid
This commit is contained in:
parent
c8a47c0bca
commit
21ac600c16
@ -242,19 +242,26 @@ static int impl_unit_equality(lua_State* L)
|
|||||||
static int impl_unit_tostring(lua_State* L)
|
static int impl_unit_tostring(lua_State* L)
|
||||||
{
|
{
|
||||||
const lua_unit* lu = luaW_tounit_ref(L, 1);
|
const lua_unit* lu = luaW_tounit_ref(L, 1);
|
||||||
unit &u = *lu->get();
|
unit* u = lu->get();
|
||||||
std::ostringstream str;
|
std::ostringstream str;
|
||||||
|
|
||||||
str << "unit: <";
|
str << "unit: <";
|
||||||
if(!u.id().empty()) {
|
if(!u) {
|
||||||
str << u.id() << " ";
|
str << "invalid";
|
||||||
|
} else if(!u->id().empty()) {
|
||||||
|
str << u->id() << " ";
|
||||||
} else {
|
} else {
|
||||||
str << u.type_id() << " ";
|
str << u->type_id() << " ";
|
||||||
}
|
}
|
||||||
if(int side = lu->on_recall_list()) {
|
if(u) {
|
||||||
str << "at (side " << side << " recall list)";
|
if(int side = lu->on_recall_list()) {
|
||||||
} else {
|
str << "at (side " << side << " recall list)";
|
||||||
str << "at (" << u.get_location() << ")";
|
} else {
|
||||||
|
if(!lu->on_map()) {
|
||||||
|
str << "private ";
|
||||||
|
}
|
||||||
|
str << "at (" << u->get_location() << ")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
str << '>';
|
str << '>';
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user