[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Undefined behaviour in luaL_checkversion_()
- From: Thomas Fields <thomasmfields@...>
- Date: Wed, 12 Sep 2012 14:36:35 +0100
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.