lua-users home
lua-l archive

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


On 04/06/2022 23:21, Luiz Henrique de Figueiredo wrote:
I fixed a bug I found with the 'l_str2int' function that caused an
integer overflow when parsing hex numbers.

It's not a bug. The manual says "if the value overflows, it wraps
around to fit into a valid integer."
https://www.lua.org/manual/5.4/manual.html#3.1

Is this behavior new for Lua 5.4 compared with Lua 5.3?
The manuals differ in this respect:

------------------------- Lua 5.4 --------------------------------------
A numeric constant with a radix point or an exponent denotes a float; otherwise, if its value fits in an integer or it is a hexadecimal constant, it denotes an integer; otherwise (that is, a decimal integer numeral that overflows), it denotes a float. Hexadecimal numerals with neither a radix point nor an exponent always denote an integer value; if the value overflows, it wraps around to fit into a valid integer.
-----------------------------------------------------------------------


----------------------- Lua 5.3 ----------------------------------------
A numeric constant with a radix point or an exponent denotes a float; otherwise, if its value fits in an integer, it denotes an integer.
-----------------------------------------------------------------------

Is this new behavior or 5.3 already behaved like this, but it was not documented?

Cheers!

-- Lorenzo