@@ -42,21 +42,27 @@ class CScriptArgReader
4242 //
4343 // Read next number
4444 //
45- template < class T >
45+ template < typename T >
4646 void ReadNumber ( T& outValue )
4747 {
4848 int iArgument = lua_type ( m_luaVM, m_iIndex );
4949 if ( iArgument == LUA_TNUMBER || iArgument == LUA_TSTRING )
5050 {
51- lua_Number number = lua_tonumber (m_luaVM, m_iIndex++);
51+ lua_Number number = lua_tonumber ( m_luaVM, m_iIndex++ );
52+
53+ if ( std::isnan ( number ) )
54+ {
55+ SetCustomError ( " Expected number, got NaN" , " Bad argument" );
56+ return ;
57+ }
5258
53- if (std::isnan (number) )
59+ if ( std::is_unsigned < T > () && number < 0.0 )
5460 {
55- SetCustomError ( " Expected number , got NaN " , " Bad argument" );
61+ SetCustomError ( " Expected positive value , got negative " , " Bad argument" );
5662 return ;
5763 }
5864
59- outValue = static_cast < T > (number);
65+ outValue = static_cast < T > ( number );
6066 return ;
6167 }
6268
@@ -68,17 +74,23 @@ class CScriptArgReader
6874 //
6975 // Read next number, using default if needed
7076 //
71- template < class T , class U >
77+ template < typename T, typename U >
7278 void ReadNumber ( T& outValue, const U& defaultValue )
7379 {
7480 int iArgument = lua_type ( m_luaVM, m_iIndex );
7581 if ( iArgument == LUA_TNUMBER || iArgument == LUA_TSTRING )
7682 {
77- lua_Number number = lua_tonumber (m_luaVM, m_iIndex++);
83+ lua_Number number = lua_tonumber ( m_luaVM, m_iIndex++ );
84+
85+ if ( std::isnan ( number ) )
86+ {
87+ SetCustomError ( " Expected number, got NaN" , " Bad argument" );
88+ return ;
89+ }
7890
79- if (std::isnan (number) )
91+ if ( std::is_unsigned < T > () && number < 0.0 )
8092 {
81- SetCustomError ( " Expected number , got NaN " , " Bad argument" );
93+ SetCustomError ( " Expected positive value , got negative " , " Bad argument" );
8294 return ;
8395 }
8496
0 commit comments