diff options
author | Richard Yao <[email protected]> | 2022-11-29 12:53:33 -0500 |
---|---|---|
committer | GitHub <[email protected]> | 2022-11-29 09:53:33 -0800 |
commit | 587a39b7290b8437dbc15edbf679f33d72459df0 (patch) | |
tree | 8b57c892a447f704a0ba06c88d8bc1ea7831e517 /module | |
parent | d6df4441c03ae1fb90f57b125d2c4813cc1561ca (diff) |
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 <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Richard Yao <[email protected]>
Closes #14204
Diffstat (limited to 'module')
-rw-r--r-- | module/lua/lobject.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/module/lua/lobject.c b/module/lua/lobject.c index f74dacdf5..ea1f9a8e3 100644 --- a/module/lua/lobject.c +++ b/module/lua/lobject.c @@ -143,7 +143,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 |