Re: An unsigned overflow in luai_makeseed()
Francisco Olarte <[email protected]>
| Newsgroups | gmane.comp.lang.lua.general |
|---|---|
| Message-ID | <CA+bJJbzSsKZaGJmSfSROUT0qCuajmk_nd1thkV9DBbKj1FXhqg@mail.gmail.com> |
Hi Sergey: On Tue, 17 Feb 2026 at 10:50, Sergey Bronnikov <[email protected]> wrote: > the function luai_makeseed() in lauxlib.c has the following expression [1]: > res ^= (res >> 3) + (res << 7) + buff[i]; > where res has type "unsigned integer". This arithmetic has an unsigned > overflow. > This is of course undefined behavior from a language point of view, but > maybe it is used here intentionally? > My C is a bit rusty, but IIRC in C/C++ unsigned overflow is defined to be modulo 2^n, signed overflow is the one with nasal demons risk. ( that code is a classic way to do bit mixing expecting wraparound ). Francisco Olarte. -- You received this message because you are subscribed to the Google Groups "lua-l" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/lua-l/CA%2BbJJbzSsKZaGJmSfSROUT0qCuajmk_nd1thkV9DBbKj1FXhqg%40mail.gmail.com.