Reject NaN and Inf in check_v3d() too

check_v2f() was already doing this
This commit is contained in:
sfan5 2025-05-19 17:44:59 +02:00
parent ec16fb33d0
commit 6ca9d75f0b
2 changed files with 16 additions and 0 deletions

View File

@ -199,6 +199,9 @@ v3d check_v3d(lua_State *L, int index)
double y = lua_tonumber(L, -2); double y = lua_tonumber(L, -2);
double z = lua_tonumber(L, -1); double z = lua_tonumber(L, -1);
lua_pop(L, 3); lua_pop(L, 3);
CHECK_FLOAT(x, "x");
CHECK_FLOAT(y, "y");
CHECK_FLOAT(z, "z");
return v3d(x, y, z); return v3d(x, y, z);
} }

View File

@ -180,4 +180,17 @@ void TestScriptApi::testVectorReadMix(MyScriptApi *script)
EXCEPTION_CHECK(LuaError, check_v3s16(L, -1)); EXCEPTION_CHECK(LuaError, check_v3s16(L, -1));
lua_pop(L, 1); lua_pop(L, 1);
} }
// same but even the result is undefined
const char *errs2[] = {
"return {x=0, y=0, z=0/0}", // nan
"return {x=0, y=0, z=math.huge}", // inf
};
for (auto &it : errs2) {
infostream << it << std::endl;
run(L, it, 1);
(void)read_v3s16(L, -1);
EXCEPTION_CHECK(LuaError, check_v3s16(L, -1));
lua_pop(L, 1);
}
} }