[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Undefined behaviour in luaL_checkversion_()
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 12 Sep 2012 10:57:49 -0300
> 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-negativefor
> 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)))
Many thanks for the report.
-- Roberto