Patch 9.0.0804

4 views
Skip to first unread message

Bram Moolenaar

unread,
Oct 20, 2022, 9:18:17 AM10/20/22
to vim...@googlegroups.com

Patch 9.0.0804
Problem: Crash when trying to divice the largest negative number by -1.
Solution: Handle this case specifically.
Files: src/eval.c, src/testdir/test_expr.vim


*** ../vim-9.0.0803/src/eval.c 2022-10-10 12:42:52.472239813 +0100
--- src/eval.c 2022-10-20 14:13:17.832852610 +0100
***************
*** 66,71 ****
--- 66,77 ----
else
result = VARNUM_MAX;
}
+ else if (n1 == VARNUM_MIN && n2 == -1)
+ {
+ // specific case: trying to do VARNUM_MIN / -1 results in a positive
+ // number that doesn't fit in varnumber_T and causes an FPE
+ result = VARNUM_MAX;
+ }
else
result = n1 / n2;

***************
*** 6023,6029 ****
}

/*
! * Convert list in "arg" into position "psop" and optional file number "fnump".
* When "fnump" is NULL there is no file number, only 3 items: [lnum, col, off]
* Note that the column is passed on as-is, the caller may want to decrement
* it to use 1 for the first column.
--- 6029,6035 ----
}

/*
! * Convert list in "arg" into position "posp" and optional file number "fnump".
* When "fnump" is NULL there is no file number, only 3 items: [lnum, col, off]
* Note that the column is passed on as-is, the caller may want to decrement
* it to use 1 for the first column.
*** ../vim-9.0.0803/src/testdir/test_expr.vim 2022-09-21 21:59:58.273433517 +0100
--- src/testdir/test_expr.vim 2022-10-20 14:12:37.344925928 +0100
***************
*** 761,766 ****
--- 761,772 ----
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
*** ../vim-9.0.0803/src/version.c 2022-10-20 13:28:43.777615365 +0100
--- src/version.c 2022-10-20 14:13:53.604789581 +0100
***************
*** 697,698 ****
--- 697,700 ----
{ /* Add new patch number below this line */
+ /**/
+ 804,
/**/

--
I am always surprised in the Linux world how quickly solutions can be
obtained. (Imagine sending an email to Bill Gates, asking why Windows
crashed, and how to fix it... and then getting an answer that fixed the
problem... <0>_<0> !) -- Mark Langdon

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages