1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-18 10:38:31 +02:00

Add bounds checks to room propety getters and setters

It is no longer possible to cause Undefined Behavior via accessing
out-of-bounds room properties.

What happens instead is - if you attempt to fetch an out-of-bounds room
property, you get a "blank" room property that just has all of the
defaults, plus its tileset is 1 because all tilesets that are nonzero
use tiles2.png, and it closely emulates the previous behavior where it
was some bogus value but definitely not zero. Its Direct Mode is also 1,
because the tiles contained within it are just mishmashed repeats of
existing tiles on the map, and we shouldn't autotile that.

The roomname also gets cleared in case the user attempts to set the room
name of an out-of-bounds room property.

If you attempt to set the property of an out-of-bounds room property,
then nothing happens.
This commit is contained in:
Misa 2021-03-24 12:04:06 -07:00 committed by Ethan Lee
parent 945d5f244a
commit b340a6ccc4

View File

@ -1032,7 +1032,17 @@ const edlevelclass* editorclass::getroomprop(const int rx, const int ry)
{
const int idx = getroompropidx(rx, ry);
return &level[idx];
if (INBOUNDS_ARR(idx, level))
{
return &level[idx];
}
static edlevelclass blank;
blank.tileset = 1;
blank.directmode = 1;
blank.roomname.clear();
return ␣
}
#define FOREACH_PROP(NAME, TYPE) \
@ -1040,6 +1050,11 @@ void editorclass::setroom##NAME(const int rx, const int ry, const TYPE NAME) \
{ \
const int idx = getroompropidx(rx, ry); \
\
if (!INBOUNDS_ARR(idx, level)) \
{ \
return; \
} \
\
level[idx].NAME = NAME; \
}