lua-users home
lua-l archive

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


On Fri, 6 Jan 2023 at 08:51, bil til <biltil52@gmail.com> wrote:
> If you would count this as "overflow/invalid", then presumably every
> Lua (or C) Code like this also would show some overflow:
>     i= 1 << 65;

This is fine in lua, perfectly defined, but in C/C++ it triggers UB
unless your ints have 65 or more bits.

But the original code:
h ^= ((h<<5) + (h>>2) + cast_byte(str[l - 1]));

can have a DEFINED overflow, i.e. in 32 bit with h=0xFF'FF'FF'FF and a
null-filled str you can be doing 0xFF'FF'FF'E0 + 0x3F'FF'FF'FF + 0
which overflows in addition and is folded modulo 2^32. This is one
thing a linter or a sanitizer, may decide to signal as it may indicate
a problem, although it is the desired behaviour here many unsigned
integer wraparounds are unintended overflows.

Francisco Olarte.