From b08d3334a2ac31df8e331e422db6c217aadac7ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B5=D1=80=D1=85=D0=B0=D1=80=D0=B4=20PICCORO=20Len?= =?UTF-8?q?z=20McKAY?= Date: Fri, 3 Jun 2022 16:21:31 -0400 Subject: [PATCH] Invalid float vector dimension range: clamp and warn instead of crash * backported from https://github.com/minetest/minetest/pull/12389 * issues related: * https://github.com/minetest/minetest/issues/11742 * https://github.com/minetest/minetest/issues/6129 * close https://codeberg.org/minenux/minetest-engine-minetest/issues/4 --- src/script/common/c_converter.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index 3c2f75641..70ad3415e 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -42,11 +42,13 @@ extern "C" { #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 "' " << \ + warningstream << "Invalid float vector dimension range '" name "' " << \ "(expected " << F1000_MIN << " < " name " < " << F1000_MAX << \ - " got " << value << ")." << std::endl; \ - throw LuaError(error_text.str()); \ + " got " << value << "). restarted to max / min" << std::endl; \ + if (value < F1000_MIN) \ + value = F1000_MIN; \ + else \ + value = F1000_MAX; \ } #define CHECK_POS_TAB(index) CHECK_TYPE(index, "position", LUA_TTABLE)