Guard all cases obj.getteleporter() is used unchecked

obj.getteleporter() is able to return -1. If there's no check on it, it
will end up indexing out-of-bounds, which is Undefined Behavior.
This commit is contained in:
Misa
2020-06-12 19:31:08 -07:00
committed by Ethan Lee
parent 3b76713441
commit 08e47e839f
3 changed files with 57 additions and 21 deletions

View File

@@ -1608,8 +1608,11 @@ void gameinput()
obj.entities[player].colour = 102;
int teleporter = obj.getteleporter();
obj.entities[teleporter].tile = 6;
obj.entities[teleporter].colour = 102;
if (teleporter > -1)
{
obj.entities[teleporter].tile = 6;
obj.entities[teleporter].colour = 102;
}
//which teleporter script do we use? it depends on the companion!
game.state = 4000;
game.statedelay = 0;
@@ -1641,8 +1644,11 @@ void gameinput()
if(companion>-1) obj.entities[companion].colour = 102;
int teleporter = obj.getteleporter();
obj.entities[teleporter].tile = 6;
obj.entities[teleporter].colour = 102;
if (teleporter > -1)
{
obj.entities[teleporter].tile = 6;
obj.entities[teleporter].colour = 102;
}
//which teleporter script do we use? it depends on the companion!
game.state = 3000;
game.statedelay = 0;
@@ -2113,8 +2119,11 @@ void teleporterinput()
obj.entities[i].colour = 102;
i = obj.getteleporter();
obj.entities[i].tile = 6;
obj.entities[i].colour = 102;
if (i > -1)
{
obj.entities[i].tile = 6;
obj.entities[i].colour = 102;
}
//which teleporter script do we use? it depends on the companion!
game.state = 4000;
game.statedelay = 0;