Lua: Fix bad bitshift in lua_strx2number()

The port of lua to OpenZFS modified lua to use int64_t for numbers
instead of double. As part of this, a function for calculating
exponentiation was replaced with a bit shift. Unfortunately, it did not
handle negative values. Also, it only supported exponents numbers with
7 digits before before overflow. This supports exponents up to 15 digits
before overflow.

Clang's static analyzer reported this as "Result of operation is garbage
or undefined" because the exponent was negative.

Reviewed-by: Damian Szuberski <szuberskidamian@gmail.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #14204
This commit is contained in:
Richard Yao 2022-11-29 12:53:33 -05:00 committed by Tony Hutter
parent 3d1e808096
commit 0e3abd2994
1 changed files with 1 additions and 1 deletions

View File

@ -144,7 +144,7 @@ static lua_Number lua_strx2number (const char *s, char **endptr) {
*endptr = cast(char *, s); /* valid up to here */
ret:
if (neg) r = -r;
return (r * (1 << e));
return ((e >= 0) ? (r * (1ULL << e)) : (r / (1ULL << -e)));
}
#endif