summaryrefslogtreecommitdiff
path: root/src/script/common
diff options
context:
space:
mode:
authorFoghrye4 <foghrye4@gmail.com>2016-10-23 20:45:25 +0300
committerNer'zhul <nerzhul@users.noreply.github.com>2016-10-25 21:10:51 +0200
commit6eb6e75fff91f86d0e59d337f12ec93fcf9dc46e (patch)
tree0b4c4447bf0ad8acd7aa18bff5eee82c852e8186 /src/script/common
parent3db2f08ff95a2e1366b9b5079100b6a681f1e562 (diff)
downloadminetest-6eb6e75fff91f86d0e59d337f12ec93fcf9dc46e.tar.gz
minetest-6eb6e75fff91f86d0e59d337f12ec93fcf9dc46e.tar.bz2
minetest-6eb6e75fff91f86d0e59d337f12ec93fcf9dc46e.zip
Adding LuaError on attempt to assign vectors with values out of range
Diffstat (limited to 'src/script/common')
-rw-r--r--src/script/common/c_converter.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp
index 857300fa5..f36298915 100644
--- a/src/script/common/c_converter.cpp
+++ b/src/script/common/c_converter.cpp
@@ -23,6 +23,7 @@ extern "C" {
}
#include "util/numeric.h"
+#include "util/serialize.h"
#include "util/string.h"
#include "common/c_converter.h"
#include "constants.h"
@@ -37,6 +38,14 @@ extern "C" {
} \
} while(0)
#define CHECK_POS_COORD(name) CHECK_TYPE(-1, "position coordinate '" name "'", LUA_TNUMBER)
+#define CHECK_FLOAT_RANGE(value, name) \
+if (value < F1000_MIN || value > F1000_MAX) { \
+ std::ostringstream error_text; \
+ error_text << "Invalid float vector dimension range '" name "' " << \
+ "(expected " << F1000_MIN << " < " name " < " << F1000_MAX << \
+ " got " << value << ")." << std::endl; \
+ throw LuaError(error_text.str()); \
+}
#define CHECK_POS_TAB(index) CHECK_TYPE(index, "position", LUA_TTABLE)
@@ -170,14 +179,17 @@ v3f check_v3f(lua_State *L, int index)
lua_getfield(L, index, "x");
CHECK_POS_COORD("x");
pos.X = lua_tonumber(L, -1);
+ CHECK_FLOAT_RANGE(pos.X, "x")
lua_pop(L, 1);
lua_getfield(L, index, "y");
CHECK_POS_COORD("y");
pos.Y = lua_tonumber(L, -1);
+ CHECK_FLOAT_RANGE(pos.Y, "y")
lua_pop(L, 1);
lua_getfield(L, index, "z");
CHECK_POS_COORD("z");
pos.Z = lua_tonumber(L, -1);
+ CHECK_FLOAT_RANGE(pos.Z, "z")
lua_pop(L, 1);
return pos;
}