]> granicus.if.org Git - vim/commitdiff
patch 8.2.2376: Vim9: crash when dividing by zero in compiled code v8.2.2376
authorBram Moolenaar <Bram@vim.org>
Tue, 19 Jan 2021 21:16:41 +0000 (22:16 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 19 Jan 2021 21:16:41 +0000 (22:16 +0100)
Problem:    Vim9: crash when dividing by zero in compiled code using
            constants.
Solution:   Call num_divide() and num_modulus(). (closes #7704)

src/testdir/test_vim9_expr.vim
src/version.c
src/vim9compile.c

index a45d0eae6e49ff1b3b3a89e61dcbe777f72a762f..c81468cb36eb17cfead7c5a6b593557746729c37 100644 (file)
@@ -1376,6 +1376,7 @@ def Test_expr6()
       assert_equal(1, g:anint / 6)
       assert_equal(2, g:anint
                             / g:thefour)
+      assert_true(1 / 0 > 99999)
 
       assert_equal(5, 11 % 6)
       assert_equal(4, g:anint % 6)
@@ -1383,6 +1384,7 @@ def Test_expr6()
                             g:anint)
       assert_equal(2, g:anint
                             % g:thefour)
+      assert_equal(0, 1 % 0)
 
       assert_equal(4, 6 * 4 / 6)
 
index 452fa2d22f996a6ce1f6ec4d21bd021dd30255b4..b809cb2b7e4bca116f56ff218a3d1235c4281ce8 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2376,
 /**/
     2375,
 /**/
index d1df00821c786ce7babf82a2a91070b093a554a0..36fd2534c3677367c474d15dee6276ccdf9cc99a 100644 (file)
@@ -4300,9 +4300,11 @@ compile_expr6(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
            {
                case '*': res = tv1->vval.v_number * tv2->vval.v_number;
                          break;
-               case '/': res = tv1->vval.v_number / tv2->vval.v_number;
+               case '/': res = num_divide(tv1->vval.v_number,
+                                                          tv2->vval.v_number);
                          break;
-               case '%': res = tv1->vval.v_number % tv2->vval.v_number;
+               case '%': res = num_modulus(tv1->vval.v_number,
+                                                          tv2->vval.v_number);
                          break;
            }
            tv1->vval.v_number = res;