fix number2integer conversion in ESP8266 for floating-point builds (#2609)

This commit is contained in:
Javier Peletier 2019-01-15 14:00:37 +01:00 committed by Terry Ellison
parent b126c6b2d2
commit c6653b5921
1 changed files with 13 additions and 3 deletions

View File

@ -717,8 +717,18 @@ union luai_Cast { double l_d; long l_l; };
/* this option always works, but may be slow */ /* this option always works, but may be slow */
#else #else
#define lua_number2int(i,d) ((i)=(int)(d))
#define lua_number2integer(i,d) ((i)=(lua_Integer)(d)) #ifdef LUA_NUMBER_INTEGRAL
#define lua_number2int(i, d) ((i) = (int)(d))
#define lua_number2integer(i, d) ((i) = (lua_Integer)(d))
#else // for floating-point builds, cast to a larger integer first to avoid undefined behavior on overflows.
#define lua_number2int(i, d) ((i) = (int)(long long)(d))
#define lua_number2integer(i, d) ((i) = (lua_Integer)(long long)(d))
#endif // LUA_NUMBER_INTEGRAL
#endif #endif