Check that LuaEntitySAO::setVelocity is not NaN

This commit is contained in:
Perttu Ahola 2015-11-01 19:52:57 +02:00
parent 9269a0ecc7
commit 1fcea9112b
3 changed files with 11 additions and 0 deletions

View File

@ -617,6 +617,9 @@ void LuaEntitySAO::notifyObjectPropertiesModified()
void LuaEntitySAO::setVelocity(v3f velocity) void LuaEntitySAO::setVelocity(v3f velocity)
{ {
if(util_isnan(velocity.X) || util_isnan(velocity.Y) ||
util_isnan(velocity.Z))
throw BaseException("LuaEntitySAO::setVelocity(): Given value is NaN");
m_velocity = velocity; m_velocity = velocity;
} }

View File

@ -179,6 +179,12 @@ v3f check_v3f(lua_State *L, int index)
CHECK_POS_COORD("z"); CHECK_POS_COORD("z");
pos.Z = lua_tonumber(L, -1); pos.Z = lua_tonumber(L, -1);
lua_pop(L, 1); lua_pop(L, 1);
if(util_isnan(pos.X))
throw LuaError("NaN passed as X coordinate");
if(util_isnan(pos.Y))
throw LuaError("NaN passed as Y coordinate");
if(util_isnan(pos.Z))
throw LuaError("NaN passed as Z coordinate");
return pos; return pos;
} }

View File

@ -416,4 +416,6 @@ inline u32 npot2(u32 orig) {
return orig + 1; return orig + 1;
} }
#define util_isnan(a) (!((a)==(a)))
#endif #endif