lua-users home
lua-l archive

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


> 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