From b00650cfe909313e58aa8181474d7f016d9df94a Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 7 Mar 2020 23:15:25 -0500 Subject: vim-patch:8.2.0361: internal error when using "0" for a callback Problem: Internal error when using "0" for a callback. Solution: Give a normal error. (closes vim/vim#5743) https://github.com/vim/vim/commit/14e57909e662a43a42438e2701654af48af49b03 --- src/nvim/eval.c | 10 ++++++++++ src/nvim/testdir/test_timers.vim | 4 ++++ 2 files changed, 14 insertions(+) (limited to 'src') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index f5c5ef9e97..ca0e078e4a 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -8114,10 +8114,16 @@ void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv, bool callback_from_typval(Callback *const callback, typval_T *const arg) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { + int r = OK; + if (arg->v_type == VAR_PARTIAL && arg->vval.v_partial != NULL) { callback->data.partial = arg->vval.v_partial; callback->data.partial->pt_refcount++; callback->type = kCallbackPartial; + } else if (arg->v_type == VAR_STRING + && arg->vval.v_string != NULL + && ascii_isdigit(*arg->vval.v_string)) { + r = FAIL; } else if (arg->v_type == VAR_FUNC || arg->v_type == VAR_STRING) { char_u *name = arg->vval.v_string; func_ref(name); @@ -8126,6 +8132,10 @@ bool callback_from_typval(Callback *const callback, typval_T *const arg) } else if (arg->v_type == VAR_NUMBER && arg->vval.v_number == 0) { callback->type = kCallbackNone; } else { + r = FAIL; + } + + if (r == FAIL) { EMSG(_("E921: Invalid callback argument")); return false; } diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index 3043103270..40376a877e 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -339,4 +339,8 @@ func Test_nocatch_garbage_collect() delfunc FeedChar endfunc +func Test_timer_invalid_callback() + call assert_fails('call timer_start(0, "0")', 'E921') +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit