diff src/vim9compile.c @ 23679:e8c379b20765 v8.2.2381

patch 8.2.2381: Vim9: divide by zero does not abort expression execution Commit: https://github.com/vim/vim/commit/c5f59fab23820454f060562927ddc1397f9d479a Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jan 21 12:34:14 2021 +0100 patch 8.2.2381: Vim9: divide by zero does not abort expression execution Problem: Vim9: divide by zero does not abort expression execution. Solution: Use a "failed" flag. (issue https://github.com/vim/vim/issues/7704)
author Bram Moolenaar <Bram@vim.org>
date Thu, 21 Jan 2021 12:45:05 +0100
parents cf2904dd9691
children 0d56d4f107d8
line wrap: on
line diff
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -4291,9 +4291,10 @@ compile_expr6(char_u **arg, cctx_T *cctx
 		&& ppconst->pp_tv[ppconst_used].v_type == VAR_NUMBER
 		&& ppconst->pp_tv[ppconst_used + 1].v_type == VAR_NUMBER)
 	{
-	    typval_T *tv1 = &ppconst->pp_tv[ppconst_used];
-	    typval_T *tv2 = &ppconst->pp_tv[ppconst_used + 1];
-	    varnumber_T res = 0;
+	    typval_T	    *tv1 = &ppconst->pp_tv[ppconst_used];
+	    typval_T	    *tv2 = &ppconst->pp_tv[ppconst_used + 1];
+	    varnumber_T	    res = 0;
+	    int		    failed = FALSE;
 
 	    // both are numbers: compute the result
 	    switch (*op)
@@ -4301,12 +4302,14 @@ compile_expr6(char_u **arg, cctx_T *cctx
 		case '*': res = tv1->vval.v_number * tv2->vval.v_number;
 			  break;
 		case '/': res = num_divide(tv1->vval.v_number,
-							   tv2->vval.v_number);
+						  tv2->vval.v_number, &failed);
 			  break;
 		case '%': res = num_modulus(tv1->vval.v_number,
-							   tv2->vval.v_number);
+						  tv2->vval.v_number, &failed);
 			  break;
 	    }
+	    if (failed)
+		return FAIL;
 	    tv1->vval.v_number = res;
 	    --ppconst->pp_used;
 	}