comparison 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
comparison
equal deleted inserted replaced
23678:8548a27908be 23679:e8c379b20765
4289 4289
4290 if (ppconst->pp_used == ppconst_used + 2 4290 if (ppconst->pp_used == ppconst_used + 2
4291 && ppconst->pp_tv[ppconst_used].v_type == VAR_NUMBER 4291 && ppconst->pp_tv[ppconst_used].v_type == VAR_NUMBER
4292 && ppconst->pp_tv[ppconst_used + 1].v_type == VAR_NUMBER) 4292 && ppconst->pp_tv[ppconst_used + 1].v_type == VAR_NUMBER)
4293 { 4293 {
4294 typval_T *tv1 = &ppconst->pp_tv[ppconst_used]; 4294 typval_T *tv1 = &ppconst->pp_tv[ppconst_used];
4295 typval_T *tv2 = &ppconst->pp_tv[ppconst_used + 1]; 4295 typval_T *tv2 = &ppconst->pp_tv[ppconst_used + 1];
4296 varnumber_T res = 0; 4296 varnumber_T res = 0;
4297 int failed = FALSE;
4297 4298
4298 // both are numbers: compute the result 4299 // both are numbers: compute the result
4299 switch (*op) 4300 switch (*op)
4300 { 4301 {
4301 case '*': res = tv1->vval.v_number * tv2->vval.v_number; 4302 case '*': res = tv1->vval.v_number * tv2->vval.v_number;
4302 break; 4303 break;
4303 case '/': res = num_divide(tv1->vval.v_number, 4304 case '/': res = num_divide(tv1->vval.v_number,
4304 tv2->vval.v_number); 4305 tv2->vval.v_number, &failed);
4305 break; 4306 break;
4306 case '%': res = num_modulus(tv1->vval.v_number, 4307 case '%': res = num_modulus(tv1->vval.v_number,
4307 tv2->vval.v_number); 4308 tv2->vval.v_number, &failed);
4308 break; 4309 break;
4309 } 4310 }
4311 if (failed)
4312 return FAIL;
4310 tv1->vval.v_number = res; 4313 tv1->vval.v_number = res;
4311 --ppconst->pp_used; 4314 --ppconst->pp_used;
4312 } 4315 }
4313 else 4316 else
4314 { 4317 {