diff options
author | ZyX <kp-pav@yandex.ru> | 2015-12-26 01:18:14 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2016-02-02 00:54:00 +0300 |
commit | b2ea083eeba5a99b90e554ad0023f0d54a21b7fe (patch) | |
tree | b7680ff51bfee924219ef14521302e8f194bb32d /src | |
parent | 2873a17c55b3a056e80da54bd22af625f5891417 (diff) | |
download | rneovim-b2ea083eeba5a99b90e554ad0023f0d54a21b7fe.tar.gz rneovim-b2ea083eeba5a99b90e554ad0023f0d54a21b7fe.tar.bz2 rneovim-b2ea083eeba5a99b90e554ad0023f0d54a21b7fe.zip |
eval: Return different values when dividing by zero
Fixes #3263
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/eval.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index c360d306d4..8cf077ec19 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -4001,12 +4001,22 @@ eval6 ( * When either side is a float the result is a float. */ if (use_float) { - if (op == '*') + if (op == '*') { f1 = f1 * f2; - else if (op == '/') { - /* We rely on the floating point library to handle divide - * by zero to result in "inf" and not a crash. */ - f1 = f2 != 0 ? f1 / f2 : INFINITY; + } else if (op == '/') { + // Division by zero triggers error from AddressSanitizer + f1 = (f2 == 0 + ? ( +#ifdef NAN + f1 == 0 + ? NAN + : +#endif + (f1 > 0 + ? INFINITY + : -INFINITY) + ) + : f1 / f2); } else { EMSG(_("E804: Cannot use '%' with Float")); return FAIL; |