Guard all cases obj.getplayer() is used unchecked

obj.getplayer() can return -1, which can cause out-of-bounds indexing of
obj.entities, which is really bad. This was by far the most changes, as
obj.getplayer() is the most used entity-getting function that returns
-1, as well as the most-used function whose sentinel value goes
unchecked.

To deal with the usage of obj.getplayer() in mapclass::warpto(), I just
added general bounds checks inside that function instead of changing all
the callers.
This commit is contained in:
Misa
2020-06-12 20:36:08 -07:00
committed by Ethan Lee
parent 08e47e839f
commit beab344267
7 changed files with 784 additions and 408 deletions

View File

@@ -1605,7 +1605,10 @@ void gameinput()
music.fadeout();
int player = obj.getplayer();
obj.entities[player].colour = 102;
if (player > -1)
{
obj.entities[player].colour = 102;
}
int teleporter = obj.getteleporter();
if (teleporter > -1)
@@ -1639,7 +1642,10 @@ void gameinput()
music.fadeout();
int player = obj.getplayer();
obj.entities[player].colour = 102;
if (player > -1)
{
obj.entities[player].colour = 102;
}
int companion = obj.getcompanion();
if(companion>-1) obj.entities[companion].colour = 102;
@@ -1948,7 +1954,10 @@ void mapinput()
game.hascontrol = false;
int i = obj.getplayer();
obj.entities[i].colour = 102;
if (i > -1)
{
obj.entities[i].colour = 102;
}
//which teleporter script do we use? it depends on the companion!
game.state = 4000;
@@ -2116,7 +2125,10 @@ void teleporterinput()
game.hascontrol = false;
int i = obj.getplayer();
obj.entities[i].colour = 102;
if (i > -1)
{
obj.entities[i].colour = 102;
}
i = obj.getteleporter();
if (i > -1)