]> granicus.if.org Git - vim/commitdiff
patch 8.0.1410: hang when using count() with an empty string v8.0.1410
authorBram Moolenaar <Bram@vim.org>
Tue, 19 Dec 2017 10:55:26 +0000 (11:55 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 19 Dec 2017 10:55:26 +0000 (11:55 +0100)
Problem:    Hang when using count() with an empty string.
Solution:   Return zero for an empty string. (Dominique Pelle, closes #2465)

runtime/doc/eval.txt
src/evalfunc.c
src/testdir/test_functions.vim
src/version.c

index c621ba1ffe22956c2c0b0d34f83024e592611517..df00dc9e4d8a2416bdf5fa21247215420092450f 100644 (file)
@@ -1,4 +1,4 @@
-*eval.txt*     For Vim version 8.0.  Last change: 2017 Dec 16
+*eval.txt*     For Vim version 8.0.  Last change: 2017 Dec 19
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -3338,8 +3338,8 @@ count({comp}, {expr} [, {ic} [, {start}]])                        *count()*
                When {ic} is given and it's |TRUE| then case is ignored.
 
                When {comp} is a string then the number of not overlapping
-               occurrences of {expr} is returned.
-
+               occurrences of {expr} is returned. Zero is returned when
+               {expr} is an empty string.
 
                                                        *cscope_connection()*
 cscope_connection([{num} , {dbpath} [, {prepend}]])
index 9aacd30786735759d777154940af80ff2f36d52f..7f78a9d7079f16d82b0884bebe21fa949c1a0039 100644 (file)
@@ -2382,7 +2382,7 @@ f_count(typval_T *argvars, typval_T *rettv)
        char_u *p = argvars[0].vval.v_string;
        char_u *next;
 
-       if (!error && expr != NULL && p != NULL)
+       if (!error && expr != NULL && *expr != NUL && p != NULL)
        {
            if (ic)
            {
index d9040137c6a93c362f774b7587668d13b3bc6d7a..20e4280c155618e8ea407708cbae4b38545a83d2 100644 (file)
@@ -692,6 +692,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()
index 97f0d66ca9ddeb000c352feb1060a5744dbf786d..cf53357a711dea400851ffc4144a09e3af9bda7a 100644 (file)
@@ -771,6 +771,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1410,
 /**/
     1409,
 /**/