1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-15 01:03:38 +02:00

Add bounds checks to tile setter and getters

This removes all traces of Undefined Behavior from getting and placing
tiles.

This mimics the previous behavior (2.2 and below) as reasonably as
possible. `vmult` was previously a vector, there was a bunch of unused
space directly after the end of the usable space of the vector, which
was all filled with zeroes. The same goes for `contents`, having
previously been a vector, and so having a bunch of zeroes immediately
following the end of the in-bounds space. That's why both are 0 if you
index them out of bounds.
This commit is contained in:
Misa 2021-03-24 11:51:39 -07:00 committed by Ethan Lee
parent 344c93e754
commit cfd5be1bc5

View File

@ -951,7 +951,14 @@ int editorclass::gettileidx(
int mult;
int idx;
mult = vmult[yoff];
if (INBOUNDS_ARR(yoff, vmult))
{
mult = vmult[yoff];
}
else
{
mult = 0;
}
idx = x + rx*40 + mult;
@ -967,6 +974,11 @@ void editorclass::settile(
) {
const int idx = gettileidx(rx, ry, x, y);
if (!INBOUNDS_ARR(idx, contents))
{
return;
}
contents[idx] = t;
}
@ -978,6 +990,11 @@ int editorclass::gettile(
) {
const int idx = gettileidx(rx, ry, x, y);
if (!INBOUNDS_ARR(idx, contents))
{
return 0;
}
return contents[idx];
}
@ -986,10 +1003,22 @@ int editorclass::getabstile(const int x, const int y)
int idx;
int yoff;
yoff = vmult[y];
if (INBOUNDS_ARR(y, vmult))
{
yoff = vmult[y];
}
else
{
yoff = 0;
}
idx = x + yoff;
if (!INBOUNDS_ARR(idx, contents))
{
return 0;
}
return contents[idx];
}