Skip to content

Commit 5a2431a

Browse files
sofarparamat
authored andcommitted
Simple decorations: Fix range check for deco->deco_param2
Allow any int value, and properly range check it before casting.
1 parent 24719c6 commit 5a2431a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/script/lua_api/l_mapgen.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -972,10 +972,10 @@ int ModApiMapgen::l_register_decoration(lua_State *L)
972972
bool read_deco_simple(lua_State *L, DecoSimple *deco)
973973
{
974974
int index = 1;
975+
int param2;
975976

976977
deco->deco_height = getintfield_default(L, index, "height", 1);
977978
deco->deco_height_max = getintfield_default(L, index, "height_max", 0);
978-
deco->deco_param2 = getintfield_default(L, index, "param2", 0);
979979

980980
if (deco->deco_height <= 0) {
981981
errorstream << "register_decoration: simple decoration height"
@@ -991,11 +991,13 @@ bool read_deco_simple(lua_State *L, DecoSimple *deco)
991991
return false;
992992
}
993993

994-
if ((deco->deco_param2 < 0) || (deco->deco_param2 > 255)) {
994+
param2 = getintfield_default(L, index, "param2", 0);
995+
if ((param2 < 0) || (param2 > 255)) {
995996
errorstream << "register_decoration: param2 out of bounds (0-255)"
996997
<< std::endl;
997998
return false;
998999
}
1000+
deco->deco_param2 = (u8)param2;
9991001

10001002
return true;
10011003
}

0 commit comments

Comments
 (0)