Lua API: Fix crash if passing an out-of-bounds side to wesnoth.interface.end_turn

This commit is contained in:
Celtic Minstrel 2021-07-02 23:33:10 -04:00 committed by Celtic Minstrel
parent c90f13cf77
commit 4426f9740f

View file

@ -1671,8 +1671,9 @@ int game_lua_kernel::intf_end_turn(lua_State* L)
//note that next_player_number = 1, next_player_number = nteams+1 both set the next team to be the first team
//but the later will make the turn counter change aswell fire turn end events accoringly etc.
if (!lua_isnoneornil(L, 1)) {
int npn = luaL_checknumber(L, 1);
if (npn <= 0 /*TODO: || npn > 2*nteams*/) {
int max = 2 * teams().size();
int npn = luaL_checkinteger(L, 1);
if (npn <= 0 || npn > max) {
return luaL_argerror(L, 1, "side number out of range");
}
resources::controller->gamestate().next_player_number_ = npn;