aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
authorAuke Kok <sofar@foo-projects.org>2016-12-06 22:08:16 -0800
committerparamat <mat.gregory@virginmedia.com>2016-12-08 08:38:10 +0000
commit5a2431a9bd9a019a47cd279ac988435b075cdabe (patch)
tree6e99dc76e8e0999d8e456f08a1138e4d0ed827b5 /src/script/lua_api
parent24719c6908305c9505eafc372fb4cfbbbd2fcf70 (diff)
downloadminetest-5a2431a9bd9a019a47cd279ac988435b075cdabe.tar.gz
minetest-5a2431a9bd9a019a47cd279ac988435b075cdabe.tar.bz2
minetest-5a2431a9bd9a019a47cd279ac988435b075cdabe.zip
Simple decorations: Fix range check for deco->deco_param2
Allow any int value, and properly range check it before casting.
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_mapgen.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp
index cefea3da9..281f68e46 100644
--- a/src/script/lua_api/l_mapgen.cpp
+++ b/src/script/lua_api/l_mapgen.cpp
@@ -972,10 +972,10 @@ int ModApiMapgen::l_register_decoration(lua_State *L)
bool read_deco_simple(lua_State *L, DecoSimple *deco)
{
int index = 1;
+ int param2;
deco->deco_height = getintfield_default(L, index, "height", 1);
deco->deco_height_max = getintfield_default(L, index, "height_max", 0);
- deco->deco_param2 = getintfield_default(L, index, "param2", 0);
if (deco->deco_height <= 0) {
errorstream << "register_decoration: simple decoration height"
@@ -991,11 +991,13 @@ bool read_deco_simple(lua_State *L, DecoSimple *deco)
return false;
}
- if ((deco->deco_param2 < 0) || (deco->deco_param2 > 255)) {
+ param2 = getintfield_default(L, index, "param2", 0);
+ if ((param2 < 0) || (param2 > 255)) {
errorstream << "register_decoration: param2 out of bounds (0-255)"
<< std::endl;
return false;
}
+ deco->deco_param2 = (u8)param2;
return true;
}