lua-users home
lua-l archive

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


Hi there,

I'd like to report an issue with Lua 5.2.1.

The luaL_checkversion_() function calls:

lua_tounsigned(L, -1) != (lua_Unsigned)-0x1234)

The lua_tounsigned() function boils down to lua_tounsignedx(), which then calls lua_number2unsigned(), which is defined as:

#define lua_number2unsigned(i,n)    ((i)=(lua_Unsigned)(n))

This type of cast is undefined behaviour - see http://stackoverflow.com/questions/2490600/iphone-floats-cast-to-unsigned-ints-get-set-to-0-if-they-are-negative for more information.

The luaL_checkversion_() function passes on Windows but fails miserably on ARM chips.

One fix would be to change the define to:

#define lua_number2unsigned(i,n)    ((i)=((lua_Unsigned)(signed int)(n)))

Regards,
Tom.