diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-10-20 22:05:51 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-10-20 22:21:01 +0800 |
commit | d1484b58ae877f1423f37092c7bfdacedccfb455 (patch) | |
tree | ef4220f77bdab3f8aeea641d3a031298f63dbd30 | |
parent | be0f284ae1c9e986ac47487ce32e39e318a0d194 (diff) | |
download | rneovim-d1484b58ae877f1423f37092c7bfdacedccfb455.tar.gz rneovim-d1484b58ae877f1423f37092c7bfdacedccfb455.tar.bz2 rneovim-d1484b58ae877f1423f37092c7bfdacedccfb455.zip |
vim-patch:9.0.0804: crash when trying to divide a number by -1
Problem: Crash when trying to divice the largest negative number by -1.
Solution: Handle this case specifically.
https://github.com/vim/vim/commit/cdef1cefa2a440911c727558562f83ed9b00e16b
-rw-r--r-- | src/nvim/eval.c | 4 | ||||
-rw-r--r-- | src/nvim/testdir/test_expr.vim | 6 |
2 files changed, 10 insertions, 0 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index d9d276e8ea..245ad8d9d8 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -330,6 +330,10 @@ varnumber_T num_divide(varnumber_T n1, varnumber_T n2) } else { result = VARNUMBER_MAX; } + } else if (n1 == VARNUMBER_MIN && n2 == -1) { + // specific case: trying to do VARNUMBAR_MIN / -1 results in a positive + // number that doesn't fit in varnumber_T and causes an FPE + result = VARNUMBER_MAX; } else { result = n1 / n2; } diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index 8d3fb88541..c63a969e50 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -602,6 +602,12 @@ func Test_eval_after_if() call assert_equal('b', s:val) endfunc +func Test_divide_by_zero() + " only tests that this doesn't crash, the result is not important + echo 0 / 0 + echo 0 / 0 / -1 +endfunc + " Test for command-line completion of expressions func Test_expr_completion() CheckFeature cmdline_compl |