Browse Source

fix bounds checks (#3237)

pull/3238/head
qndel 4 years ago committed by GitHub
parent
commit
0ccdf940f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      Source/items.cpp
  2. 2
      Source/lighting.cpp
  3. 15
      Source/monster.cpp
  4. 4
      Source/path.cpp
  5. 2
      Source/player.cpp
  6. 6
      Source/scrollrt.cpp
  7. 2
      Source/track.cpp

7
Source/items.cpp

@ -3184,10 +3184,7 @@ void CreatePlrItems(int playerId)
bool ItemSpaceOk(Point position)
{
int oi;
// BUGFIX: Check `i + 1 >= MAXDUNX` and `j + 1 >= MAXDUNY` (applied)
if (position.x < 0 || position.x + 1 >= MAXDUNX || position.y < 0 || position.y + 1 >= MAXDUNY)
if (!InDungeonBounds(position))
return false;
if (dMonster[position.x][position.y] != 0)
@ -3200,7 +3197,7 @@ bool ItemSpaceOk(Point position)
return false;
if (dObject[position.x][position.y] != 0) {
oi = dObject[position.x][position.y] > 0 ? dObject[position.x][position.y] - 1 : -(dObject[position.x][position.y] + 1);
int oi = dObject[position.x][position.y] > 0 ? dObject[position.x][position.y] - 1 : -(dObject[position.x][position.y] + 1);
if (Objects[oi]._oSolidFlag)
return false;
}

2
Source/lighting.cpp

@ -648,7 +648,7 @@ void DoUnVision(Point position, int nRadius)
void DoVision(Point position, int nRadius, bool doautomap, bool visible)
{
if (position.x >= 0 && position.x <= MAXDUNX && position.y >= 0 && position.y <= MAXDUNY) {
if (InDungeonBounds(position)) {
if (doautomap) {
if (dFlags[position.x][position.y] != 0) {
SetAutomapView(position);

15
Source/monster.cpp

@ -253,8 +253,7 @@ bool CanPlaceMonster(int xp, int yp)
{
char f;
if (xp < 0 || xp >= MAXDUNX
|| yp < 0 || yp >= MAXDUNY
if (!InDungeonBounds({ xp, yp })
|| dMonster[xp][yp] != 0
|| dPlayer[xp][yp] != 0) {
return false;
@ -2479,8 +2478,8 @@ void ScavengerAi(int i)
if (GenerateRnd(2) != 0) {
for (y = -4; y <= 4 && !done; y++) {
for (x = -4; x <= 4 && !done; x++) {
// BUGFIX: incorrect check of offset against limits of the dungeon
if (y < 0 || y >= MAXDUNY || x < 0 || x >= MAXDUNX)
// BUGFIX: incorrect check of offset against limits of the dungeon (fixed)
if (!InDungeonBounds(monster.position.tile + Displacement { x, y }))
continue;
done = dCorpse[monster.position.tile.x + x][monster.position.tile.y + y] != 0
&& IsLineNotSolid(
@ -2493,8 +2492,8 @@ void ScavengerAi(int i)
} else {
for (y = 4; y >= -4 && !done; y--) {
for (x = 4; x >= -4 && !done; x--) {
// BUGFIX: incorrect check of offset against limits of the dungeon
if (y < 0 || y >= MAXDUNY || x < 0 || x >= MAXDUNX)
// BUGFIX: incorrect check of offset against limits of the dungeon (fixed)
if (!InDungeonBounds(monster.position.tile + Displacement { x, y }))
continue;
done = dCorpse[monster.position.tile.x + x][monster.position.tile.y + y] != 0
&& IsLineNotSolid(
@ -4404,7 +4403,7 @@ bool DirOK(int i, Direction mdir)
auto &monster = Monsters[i];
Point position = monster.position.tile;
Point futurePosition = position + mdir;
if (futurePosition.y < 0 || futurePosition.y >= MAXDUNY || futurePosition.x < 0 || futurePosition.x >= MAXDUNX || !IsTileAvailable(monster, futurePosition))
if (!InDungeonBounds(futurePosition) || !IsTileAvailable(monster, futurePosition))
return false;
if (mdir == Direction::East) {
if (IsTileSolid(position + Direction::SouthEast))
@ -4426,7 +4425,7 @@ bool DirOK(int i, Direction mdir)
int mcount = 0;
for (int x = futurePosition.x - 3; x <= futurePosition.x + 3; x++) {
for (int y = futurePosition.y - 3; y <= futurePosition.y + 3; y++) {
if (y < 0 || y >= MAXDUNY || x < 0 || x >= MAXDUNX)
if (!InDungeonBounds({ x, y }))
continue;
int mi = dMonster[x][y];
if (mi == 0)

4
Source/path.cpp

@ -285,7 +285,7 @@ bool GetPath(const std::function<bool(Point)> &posOk, PATHNODE *pPath, Point des
bool IsTileNotSolid(Point position)
{
if (position.x < 0 || position.y < 0 || position.x >= MAXDUNX || position.y >= MAXDUNY) {
if (!InDungeonBounds(position)) {
return false;
}
@ -294,7 +294,7 @@ bool IsTileNotSolid(Point position)
bool IsTileSolid(Point position)
{
if (position.x < 0 || position.y < 0 || position.x >= MAXDUNX || position.y >= MAXDUNY) {
if (!InDungeonBounds(position)) {
return false;
}

2
Source/player.cpp

@ -3369,7 +3369,7 @@ void ClrPlrPath(Player &player)
*/
bool PosOkPlayer(const Player &player, Point position)
{
if (position.x < 0 || position.x >= MAXDUNX || position.y < 0 || position.y >= MAXDUNY)
if (!InDungeonBounds(position))
return false;
if (dPiece[position.x][position.y] == 0)
return false;

6
Source/scrollrt.cpp

@ -95,9 +95,7 @@ std::unordered_multimap<Point, Missile *, PointHash> MissilesAtRenderingTile;
*/
bool CouldMissileCollide(Point tile, bool checkPlayerAndMonster)
{
if (tile.x >= MAXDUNX || tile.x < 0)
return true;
if (tile.y >= MAXDUNY || tile.y < 0)
if (!InDungeonBounds(tile))
return true;
if (checkPlayerAndMonster) {
if (dMonster[tile.x][tile.y] > 0)
@ -931,7 +929,7 @@ void DrawFloor(const Surface &out, Point tilePosition, Point targetBufferPositio
{
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
if (tilePosition.x >= 0 && tilePosition.x < MAXDUNX && tilePosition.y >= 0 && tilePosition.y < MAXDUNY) {
if (InDungeonBounds(tilePosition)) {
level_piece_id = dPiece[tilePosition.x][tilePosition.y];
if (level_piece_id != 0) {
if (!nSolidTable[level_piece_id])

2
Source/track.cpp

@ -18,7 +18,7 @@ namespace {
void RepeatWalk(Player &player)
{
if (cursPosition.x < 0 || cursPosition.x >= MAXDUNX - 1 || cursPosition.y < 0 || cursPosition.y >= MAXDUNY - 1)
if (!InDungeonBounds(cursPosition))
return;
if (player._pmode != PM_STAND && !(player.IsWalking() && player.AnimInfo.GetFrameToUseForRendering() > 6))

Loading…
Cancel
Save