Skip to content

Commit 338e47f

Browse files
committed
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 #2465)
1 parent 132f752 commit 338e47f

4 files changed

Lines changed: 7 additions & 4 deletions

File tree

runtime/doc/eval.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*eval.txt* For Vim version 8.0. Last change: 2017 Dec 16
1+
*eval.txt* For Vim version 8.0. Last change: 2017 Dec 19
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -3338,8 +3338,8 @@ count({comp}, {expr} [, {ic} [, {start}]]) *count()*
33383338
When {ic} is given and it's |TRUE| then case is ignored.
33393339

33403340
When {comp} is a string then the number of not overlapping
3341-
occurrences of {expr} is returned.
3342-
3341+
occurrences of {expr} is returned. Zero is returned when
3342+
{expr} is an empty string.
33433343

33443344
*cscope_connection()*
33453345
cscope_connection([{num} , {dbpath} [, {prepend}]])

src/evalfunc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2382,7 +2382,7 @@ f_count(typval_T *argvars, typval_T *rettv)
23822382
char_u *p = argvars[0].vval.v_string;
23832383
char_u *next;
23842384

2385-
if (!error && expr != NULL && p != NULL)
2385+
if (!error && expr != NULL && *expr != NUL && p != NULL)
23862386
{
23872387
if (ic)
23882388
{

src/testdir/test_functions.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ func Test_count()
692692
call assert_equal(0, count("foo", "O"))
693693
call assert_equal(2, count("foo", "O", 1))
694694
call assert_equal(2, count("fooooo", "oo"))
695+
call assert_equal(0, count("foo", ""))
695696
endfunc
696697

697698
func Test_changenr()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,8 @@ static char *(features[]) =
771771

772772
static int included_patches[] =
773773
{ /* Add new patch number below this line */
774+
/**/
775+
1410,
774776
/**/
775777
1409,
776778
/**/

0 commit comments

Comments
 (0)