Permalink
Browse files

Added a bounds check for BOMB reading pmap (#497)

  • Loading branch information...
MrZacbot authored and jacob1 committed Aug 30, 2017
1 parent 1ceae1b commit be786d85a7339d433a42abcf4f4f25da20be3c6b
Showing with 9 additions and 4 deletions.
  1. +9 −4 src/simulation/elements/BOMB.cpp
@@ -67,13 +67,18 @@ int Element_BOMB::update(UPDATE_FUNC_ARGS)
for (nxi=-rad; nxi<=rad; nxi++)
if ((pow((float)nxi,2))/(pow((float)rad,2))+(pow((float)nxj,2))/(pow((float)rad,2))<=1)
{
nt = pmap[y+nxj][x+nxi]&0xFF;
int ynxj = y + nxj, xnxi = x + nxi;
if ((ynxj < 0) || (ynxj >= YRES) || (xnxi <= 0) || (xnxi >= XRES))
continue;
nt = pmap[ynxj][xnxi]&0xFF;
if (nt!=PT_DMND && nt!=PT_CLNE && nt!=PT_PCLN && nt!=PT_BCLN && nt!=PT_VIBR)
{
if (nt)
sim->kill_part(pmap[y+nxj][x+nxi]>>8);
sim->pv[(y+nxj)/CELL][(x+nxi)/CELL] += 0.1f;
nb = sim->create_part(-3, x+nxi, y+nxj, PT_EMBR);
sim->kill_part(pmap[ynxj][xnxi]>>8);
sim->pv[(ynxj)/CELL][(xnxi)/CELL] += 0.1f;
nb = sim->create_part(-3, xnxi, ynxj, PT_EMBR);
if (nb!=-1)
{
parts[nb].tmp = 2;

0 comments on commit be786d8

Please sign in to comment.