From a44588798564dae1dc28b31af49e38399888d9a2 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 8 Aug 2018 23:16:36 -0400 Subject: vim-patch:8.0.1410: hang when using count() with an empty string Problem: Hang when using count() with an empty string. Solution: Return zero for an empty string. (Dominique Pelle, closes vim/vim#2465) https://github.com/vim/vim/commit/338e47fdfdf0d918dae50a5cbf0cf4f7be45b4f0 --- src/nvim/eval.c | 2 +- src/nvim/testdir/test_functions.vim | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index d9765af1dc..8db48062e9 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -7603,7 +7603,7 @@ static void f_count(typval_T *argvars, typval_T *rettv, FunPtr fptr) const char_u *expr = (char_u *)tv_get_string_chk(&argvars[1]); const char_u *p = argvars[0].vval.v_string; - if (!error && expr != NULL && p != NULL) { + if (!error && expr != NULL && *expr != NUL && p != NULL) { if (ic) { const size_t len = STRLEN(expr); diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 285c4e6327..63794a7a85 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -723,6 +723,7 @@ func Test_count() call assert_equal(0, count("foo", "O")) call assert_equal(2, count("foo", "O", 1)) call assert_equal(2, count("fooooo", "oo")) + call assert_equal(0, count("foo", "")) endfunc func Test_changenr() -- cgit