From b2ea083eeba5a99b90e554ad0023f0d54a21b7fe Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 26 Dec 2015 01:18:14 +0300 Subject: eval: Return different values when dividing by zero Fixes #3263 --- src/nvim/eval.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src') 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; -- cgit