diff options
author | Richard Yao <[email protected]> | 2022-11-29 12:53:33 -0500 |
---|---|---|
committer | Tony Hutter <[email protected]> | 2022-12-01 12:39:44 -0800 |
commit | 0e3abd29945b6d6a4f89892445f4d85bcb1d1e92 (patch) | |
tree | 4cd5a4e19eff61b1bd57c71ae7735f36a74eb334 /module/lua | |
parent | 3d1e8080960886cf9d542e318a400a185c521806 (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/lua')
-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 024d3199f..5d88d36c5 100644 --- a/module/lua/lobject.c +++ b/module/lua/lobject.c @@ -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 |