diff options
author | Jan Edmund Lazo <janedmundlazo@hotmail.com> | 2018-06-21 21:44:18 -0400 |
---|---|---|
committer | Jan Edmund Lazo <janedmundlazo@hotmail.com> | 2018-06-24 16:19:21 -0400 |
commit | 39e284772d5ee7214341fce9e25f9d7e051dd39e (patch) | |
tree | 17493843460c664651906fd168c45dfbff468a57 /src/nvim/eval.c | |
parent | 38fb83585421c45828a4934fc75f7952b2baf116 (diff) | |
download | rneovim-39e284772d5ee7214341fce9e25f9d7e051dd39e.tar.gz rneovim-39e284772d5ee7214341fce9e25f9d7e051dd39e.tar.bz2 rneovim-39e284772d5ee7214341fce9e25f9d7e051dd39e.zip |
vim-patch:8.0.0642: writefile() continues after detecting an error
Problem: writefile() continues after detecting an error.
Solution: Bail out as soon as an error is detected. (suggestions by Nikolai
Pavlov, closes vim/vim#1476)
https://github.com/vim/vim/commit/8cf91286ca46a501d24e4b7d631b193256782c88
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r-- | src/nvim/eval.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 86ed9052aa..8d45863d6f 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -17675,7 +17675,7 @@ static void f_wordcount(typval_T *argvars, typval_T *rettv, FunPtr fptr) /// "writefile()" function static void f_writefile(typval_T *argvars, typval_T *rettv, FunPtr fptr) { - rettv->vval.v_number = 0; // Assuming success. + rettv->vval.v_number = -1; if (check_restricted() || check_secure()) { return; @@ -17685,6 +17685,12 @@ static void f_writefile(typval_T *argvars, typval_T *rettv, FunPtr fptr) EMSG2(_(e_listarg), "writefile()"); return; } + const list_T *const list = argvars[0].vval.v_list; + TV_LIST_ITER_CONST(list, li, { + if (!tv_check_str_or_nr(TV_LIST_ITEM_TV(li))) { + return; + } + }); bool binary = false; bool append = false; @@ -17716,7 +17722,6 @@ static void f_writefile(typval_T *argvars, typval_T *rettv, FunPtr fptr) } FileDescriptor fp; int error; - rettv->vval.v_number = -1; if (*fname == NUL) { EMSG(_("E482: Can't open file with an empty name")); } else if ((error = file_open(&fp, fname, @@ -17725,7 +17730,7 @@ static void f_writefile(typval_T *argvars, typval_T *rettv, FunPtr fptr) emsgf(_("E482: Can't open file %s for writing: %s"), fname, os_strerror(error)); } else { - if (write_list(&fp, argvars[0].vval.v_list, binary)) { + if (write_list(&fp, list, binary)) { rettv->vval.v_number = 0; } if ((error = file_close(&fp, do_fsync)) != 0) { |