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:
parent
3d1e808096
commit
0e3abd2994
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue