[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: right shift undefined behavior with mininteger (5.4.3)
- From: Roberto Ierusalimschy <roberto@...>
- Date: Thu, 22 Jul 2021 10:35:30 -0300
> If I'm not mistaken this is undefined behavior (of the C kind):
>
> 1 >> math.mininteger
>
> due to the following in lvm.c:
>
> #define luaV_shiftr(x,y) luaV_shiftl(x,-(y))
>
> Perhaps it should use `intop(-, 0, y)` instead of plain negation?
>
> I don't know if this is a thing that anyone cares about, but I thought I'd
> point it out just in case.
We care. If we compile Lua with -fsanitize=undefined, the issue is clear:
> 1 >> math.mininteger
lvm.c:1472:9: runtime error: negation of -9223372036854775808 cannot be represented in type 'long long int'; cast to an unsigned type to negate this value to itself
Thanks for the report.
-- Roberto