lua-users home
lua-l archive

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


the parser also incorrectly "upgrades" a valid integer to a float value with a minimum integer value:

tonumber is correct here:
> tonumber('-9223372036854775808',10)
-9223372036854775808

lexical parse is not
> -9223372036854775808
-9.2233720368548e+18

> math.mininteger
-9223372036854775808
> math.type(-9223372036854775808)
float
> math.type(math.mininteger)
integer



From: Payo Nel
Sent: Thursday, March 26, 2020 5:36 PM
To: lua-l@lists.lua.org <lua-l@lists.lua.org>
Subject: lexical parse of hex literal fails to handle overflow: lua 5.3 and 5.4-alpha
 
the lexical parser continues to read hex values, ignoring that the value may be overflowing the maximum integer
e.g. on 64 bit lua (5.3 and 5.4-alpha have the same issue)
> 0x7FFFFFFFFFFFFFFF
9223372036854775807
> 0xFFFFFFFFFFFFFFFF
-1
> 0xFFFFFFFFFFFFFFFFF
-1
> 0x10000000000000000
0
> 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
-1

expected:
the l_str2int should fail and the lexical parser should fall back to floats