Skip to content

Commit

Permalink
Merge pull request #2109 from tag2015/fix_overflow
Browse files Browse the repository at this point in the history
Fixes for possibile indexes out of bounds
  • Loading branch information
ivan-mogilko authored Aug 24, 2023
2 parents 9fd0aca + 48642c2 commit b7e2248
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Engine/gfx/gfx_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static const BlendModeSetter BlendModeSets[kNumBlendModes] =

bool SetBlender(BlendMode blend_mode, bool dst_has_alpha, bool src_has_alpha, int blend_alpha)
{
if (blend_mode < 0 || blend_mode > kNumBlendModes)
if (blend_mode < 0 || blend_mode >= kNumBlendModes)
return false;
const BlendModeSetter &set = BlendModeSets[blend_mode];
PfnBlenderCb blender;
Expand Down Expand Up @@ -151,7 +151,7 @@ void DrawSpriteWithTransparency(Bitmap *ds, Bitmap *sprite, int x, int y, int al
}
sprite = &hctemp;
}

if ((alpha < 0xFF) && (surface_depth > 8) && (sprite_depth > 8))
{
set_trans_blender(0, 0, 0, alpha);
Expand Down
28 changes: 14 additions & 14 deletions Plugins/agspalrender/raycast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ unsigned char selectedColor;

void Ray_SelectTile (int x,int y, unsigned char color)
{
if (x < 0 || x > mapWidth) selectedX = -1;
else if (y < 0 || y > mapWidth) selectedY = -1;
if (x < 0 || x >= mapWidth) selectedX = -1;
else if (y < 0 || y >= mapHeight) selectedY = -1;
else
{
selectedX = x;
Expand All @@ -108,8 +108,8 @@ void Ray_SelectTile (int x,int y, unsigned char color)

int Ray_HasSeenTile (int x,int y)
{
if (x < 0 || x > mapWidth) return -1;
else if (y < 0 || y > mapWidth) return -1;
if (x < 0 || x >= mapWidth) return -1;
else if (y < 0 || y >= mapHeight) return -1;
return seenMap [x][y];
}

Expand All @@ -127,8 +127,8 @@ void Ray_DrawTile (int spr,int tile)
{
BITMAP *sprite = engine->GetSpriteGraphic (spr);
unsigned char** sprarray = engine->GetRawBitmapSurface (sprite);
for (int y=0;y<64;++y)
for (int x=0;x<64;++x)
for (int y=0;y<mapHeight;++y)
for (int x=0;x<mapWidth;++x)
sprarray [y][x] = texture [tile][(texWidth * y) + x];
engine->ReleaseBitmapSurface (sprite);
}
Expand All @@ -137,8 +137,8 @@ void Ray_DrawOntoTile (int spr,int tile)
{
BITMAP *sprite = engine->GetSpriteGraphic (spr);
unsigned char** sprarray = engine->GetRawBitmapSurface (sprite);
for (int y=0;y<64;++y)
for (int x=0;x<64;++x)
for (int y=0;y<mapHeight;++y)
for (int x=0;x<mapWidth;++x)
texture [tile][(texWidth * y) + x] = sprarray [y][x];
engine->ReleaseBitmapSurface (sprite);
}
Expand Down Expand Up @@ -661,33 +661,33 @@ void MakeTextures (int slot)

void Ray_SetFloorAt (int x,int y,int tex)
{
if (x < 0 || x > mapWidth || y < 0 || y > mapHeight || tex > 511) return;
if (x < 0 || x >= mapWidth || y < 0 || y >= mapHeight || tex > 511) return;
else floorMap[x][y] = tex;
}

void Ray_SetCeilingAt (int x,int y,int tex)
{
if (x < 0 || x > mapWidth || y < 0 || y > mapHeight || tex > 511) return;
if (x < 0 || x >= mapWidth || y < 0 || y >= mapHeight || tex > 511) return;
else ceilingMap[x][y] = tex;
}

int Ray_GetCeilingAt (int x,int y)
{
if (x < 0 || x > mapWidth || y < 0 || y > mapHeight) return -1;
if (x < 0 || x >= mapWidth || y < 0 || y >= mapHeight) return -1;
else return ceilingMap [x][y];
}


int Ray_GetFloorAt (int x,int y)
{
if (x < 0 || x > mapWidth || y < 0 || y > mapHeight) return -1;
if (x < 0 || x >= mapWidth || y < 0 || y >= mapHeight) return -1;
else return floorMap [x][y];
}


int Ray_GetLightingAt (int x,int y)
{
if (x < 0 || x > mapWidth || y < 0 || y > mapHeight) return -1;
if (x < 0 || x >= mapWidth || y < 0 || y >= mapHeight) return -1;
else
{
int lighting=0;
Expand All @@ -702,7 +702,7 @@ int Ray_GetLightingAt (int x,int y)

void Ray_SetLightingAt (int x,int y,unsigned char lighting)
{
if (x < 0 || x > mapWidth || y < 0 || y > mapHeight) return;
if (x < 0 || x >= mapWidth || y < 0 || y >= mapHeight) return;
else
{
lightMap [x][y] = lighting;
Expand Down

0 comments on commit b7e2248

Please sign in to comment.