1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-26 06:28:30 +02:00

Add bounds checks to indexing of global "temporary" variable k

For some reason, the variable `k` is on entityclass and gets mutated in
createentity() and createblock(). Then updateentities() uses it without
checking if it's valid, because either `k` or the size of `entities`
could have changed in the meantime. To fix any potential undefined
behavior, these bounds checks should be added.
This commit is contained in:
Misa 2020-09-25 14:08:34 -07:00 committed by Ethan Lee
parent 990ee63a6e
commit a38faad156

View File

@ -2736,8 +2736,8 @@ bool entityclass::updateentities( int i )
if (entities[i].state == 1)
{
//happy!
if (entities[k].rule == 6) entities[k].tile = 0;
if (entities[k].rule == 7) entities[k].tile = 6;
if (INBOUNDS_VEC(k, entities) && entities[k].rule == 6) entities[k].tile = 0;
if (INBOUNDS_VEC(k, entities) && entities[k].rule == 7) entities[k].tile = 6;
//Stay close to the hero!
int j = getplayer();
if (INBOUNDS_VEC(j, entities) && entities[j].xp > entities[i].xp + 5)