fix two potential crashes

This commit is contained in:
Tim Felgentreff 2022-02-16 08:42:39 +01:00
parent e1c16e1ef6
commit 8dfb7bcf67
2 changed files with 9 additions and 5 deletions

View file

@ -255,8 +255,10 @@ bool UnitTypeCanBeAt(const CUnitType &type, const Vec2i &pos)
for (int addy = 0; addy < type.TileHeight; ++addy) {
for (int addx = 0; addx < type.TileWidth; ++addx) {
if (Map.Info.IsPointOnMap(pos.x + addx, pos.y + addy) == false
|| Map.Field(pos.x + addx + index)->CheckMask(mask) == true) {
if (!Map.Info.IsPointOnMap(pos.x + addx, pos.y + addy)) {
return false;
}
if (!type.BoolFlag[NONSOLID_INDEX].value && Map.Field(pos.x + addx + index)->CheckMask(mask)) {
return false;
}
}
@ -276,9 +278,6 @@ bool UnitTypeCanBeAt(const CUnitType &type, const Vec2i &pos)
bool UnitCanBeAt(const CUnit &unit, const Vec2i &pos)
{
Assert(unit.Type);
if (unit.Type->BoolFlag[NONSOLID_INDEX].value) {
return true;
}
return UnitTypeCanBeAt(*unit.Type, pos);
}

View file

@ -925,6 +925,11 @@ static int CclGetTileTerrainHasFlag(lua_State *l)
LuaCheckArgs(l, 3);
const Vec2i pos(LuaToNumber(l, 1), LuaToNumber(l, 2));
if (pos.x >= Map.Info.MapWidth || pos.y >= Map.Info.MapHeight || pos.x < 0 || pos.y < 0) {
// out of bounds, doesn't have it
lua_pushboolean(l, 0);
return 1;
}
unsigned short flag = 0;
const char *flag_name = LuaToString(l, 3);