Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for possibile indexes out of bounds #2109

Merged
merged 3 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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