mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 11:28:22 +00:00
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.
cdef1cefa2
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user