lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> We run Lua 5.2 in an embedded device and have changed lua_Number to
> the C type int.
> 
> There are a few problems with this in the new Lua 5.2
> 
> In lstrlib.c line 883, please consider changing:
> luaL_argcheck(L, 0 <= n && n < (MAX_UINTFRM + 1), arg,
> to:
> luaL_argcheck(L, 0 <= n && (unsigned LUA_INTFRM_T)n <= (MAX_UINTFRM), arg,

I think the following approach works for all cases:

           lua_Number n = luaL_checknumber(L, arg);
-          luaL_argcheck(L, 0 <= n && n < (MAX_UINTFRM + 1), arg,
+          unsigned LUA_INTFRM_T ni = (unsigned LUA_INTFRM_T)n;
+          lua_Number diff = n - (lua_Number)ni;
+          luaL_argcheck(L, -1 < diff && diff < 1, arg,
                         "not a non-negative number in proper range");

-- Roberto