From c1cfcdb47206b87cbee1edd82e650c48867b7d95 Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Sun, 4 Feb 2018 12:49:00 +1100 Subject: [PATCH] Lua: don't allow setting a unit's x,y coordinated to an off-map location --- src/scripting/lua_unit.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/scripting/lua_unit.cpp b/src/scripting/lua_unit.cpp index 8a3d9fc48d5f..82ee35de49f4 100644 --- a/src/scripting/lua_unit.cpp +++ b/src/scripting/lua_unit.cpp @@ -14,9 +14,11 @@ #include "scripting/lua_unit.hpp" +#include "formatter.hpp" #include "game_board.hpp" #include "log.hpp" #include "map/location.hpp" // for map_location +#include "map/map.hpp" #include "resources.hpp" #include "scripting/lua_common.hpp" #include "scripting/lua_unit_attacks.hpp" @@ -463,6 +465,12 @@ static int impl_unit_set(lua_State *L) // TODO: could probably be relegated to a helper function. if(src != dst) { + // If the dst isn't on the map, the unit will be clobbered. Guard against that. + if(!gb->map().on_board(dst)) { + std::string err_msg = formatter() << "destination hex not on map (excluding border): " << dst; + return luaL_argerror(L, 2, err_msg.c_str()); + } + unit_map::iterator u = gb->units().end(); bool success = false;