cc-tweaked / Cobalt

A re-entrant fork of LuaJ
Other
72 stars 13 forks source link

Integers being parsed into long results in inconsistencies #88

Closed Kan18 closed 3 weeks ago

Kan18 commented 1 month ago

When the Lua parser reads 9999999999999999999, it overflows and results in -8446744073709551616. In contrast, all the versions of Lua I tested will parse it into a floating-point number.

image

Also, when the Lua parser reads 0xffffffffffffffff, it overflows and results in -1. This does not happen in Lua 5.2. The Lua 5.3/5.4 reference manual (see section 3.1) specifies this to be the correct behavior for hexadecimal integers, but since Cobalt doesn't have the Lua 5.3 integer subtype I don't think it should do this either. I haven't tested it yet, but this could probably be fixed by something like:

try {
    x = Math.addExact(Math.multiplyExact(x, base), digit);
} catch (ArithmeticException e) {
    return Double.NaN;
}

in NumberParser::scanLong.