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

This commit is contained in:
MrZacbot
2017-08-30 01:44:14 +01:00
committed by jacob1
parent 1ceae1ba43
commit be786d85a7

View File

@@ -67,13 +67,18 @@ int Element_BOMB::update(UPDATE_FUNC_ARGS)
for (nxi=-rad; nxi<=rad; nxi++) for (nxi=-rad; nxi<=rad; nxi++)
if ((pow((float)nxi,2))/(pow((float)rad,2))+(pow((float)nxj,2))/(pow((float)rad,2))<=1) 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!=PT_DMND && nt!=PT_CLNE && nt!=PT_PCLN && nt!=PT_BCLN && nt!=PT_VIBR)
{ {
if (nt) if (nt)
sim->kill_part(pmap[y+nxj][x+nxi]>>8); sim->kill_part(pmap[ynxj][xnxi]>>8);
sim->pv[(y+nxj)/CELL][(x+nxi)/CELL] += 0.1f; sim->pv[(ynxj)/CELL][(xnxi)/CELL] += 0.1f;
nb = sim->create_part(-3, x+nxi, y+nxj, PT_EMBR); nb = sim->create_part(-3, xnxi, ynxj, PT_EMBR);
if (nb!=-1) if (nb!=-1)
{ {
parts[nb].tmp = 2; parts[nb].tmp = 2;