mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-23 02:03:01 +08:00
tinyexpr: Prevent possible division by zero
This is possibly not actually undefined behavior because IEEE754 defines _more_ of division-by-zero, but let's be careful. Fixes #2852.
This commit is contained in:
parent
4cc168ae11
commit
9f469e576b
|
@ -202,7 +202,13 @@ static const te_builtin *find_builtin(const char *name, int len) {
|
|||
static constexpr double add(double a, double b) {return a + b;}
|
||||
static constexpr double sub(double a, double b) {return a - b;}
|
||||
static constexpr double mul(double a, double b) {return a * b;}
|
||||
static constexpr double divide(double a, double b) {return a / b;}
|
||||
static constexpr double divide(double a, double b) {
|
||||
// If b isn't zero, divide.
|
||||
// If a isn't zero, return signed INFINITY.
|
||||
// Else, return NAN.
|
||||
return b ? a / b : a ? copysign(1, a) * copysign(1,b) * INFINITY : NAN;
|
||||
}
|
||||
|
||||
static constexpr double negate(double a) {return -a;}
|
||||
|
||||
void next_token(state *s) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user