]> granicus.if.org Git - vim/commitdiff
patch 8.1.0112: no error when using bad arguments with searchpair() v8.1.0112
authorBram Moolenaar <Bram@vim.org>
Sun, 24 Jun 2018 17:01:59 +0000 (19:01 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 24 Jun 2018 17:01:59 +0000 (19:01 +0200)
Problem:    No error when using bad arguments with searchpair().
Solution:   Add error messages.

src/evalfunc.c
src/testdir/test_search.vim
src/version.c

index 0cd7527f771a804147280c7b36f88d9f1453cb53..cec6dabb4a7a58934e657548b00adfbaa9c17185 100644 (file)
@@ -10152,7 +10152,8 @@ searchpair_cmn(typval_T *argvars, pos_T *match_pos)
     long       lnum_stop = 0;
     long       time_limit = 0;
 
-    /* Get the three pattern arguments: start, middle, end. */
+    /* Get the three pattern arguments: start, middle, end. Will result in an
+     * error if not a valid argument. */
     spat = get_tv_string_chk(&argvars[0]);
     mpat = get_tv_string_buf_chk(&argvars[1], nbuf1);
     epat = get_tv_string_buf_chk(&argvars[2], nbuf2);
@@ -10189,19 +10190,26 @@ searchpair_cmn(typval_T *argvars, pos_T *match_pos)
            && skip->v_type != VAR_STRING)
        {
            /* Type error */
+           EMSG2(_(e_invarg2), get_tv_string(&argvars[4]));
            goto theend;
        }
        if (argvars[5].v_type != VAR_UNKNOWN)
        {
            lnum_stop = (long)get_tv_number_chk(&argvars[5], NULL);
            if (lnum_stop < 0)
+           {
+               EMSG2(_(e_invarg2), get_tv_string(&argvars[5]));
                goto theend;
+           }
 #ifdef FEAT_RELTIME
            if (argvars[6].v_type != VAR_UNKNOWN)
            {
                time_limit = (long)get_tv_number_chk(&argvars[6], NULL);
                if (time_limit < 0)
+               {
+                   EMSG2(_(e_invarg2), get_tv_string(&argvars[6]));
                    goto theend;
+               }
            }
 #endif
        }
index c923e9d40288943c45eb0fdc632c743aee804e0f..9b078be396dae7abff2cae82fe4231197287d7f5 100644 (file)
@@ -287,16 +287,26 @@ func Test_searchpair()
   new
   call setline(1, ['other code here', '', '[', '" cursor here', ']'])
   4
-  let a=searchpair('\[','',']','bW')
+  let a = searchpair('\[','',']','bW')
   call assert_equal(3, a)
   set nomagic
   4
-  let a=searchpair('\[','',']','bW')
+  let a = searchpair('\[','',']','bW')
   call assert_equal(3, a)
   set magic
   q!
 endfunc
 
+func Test_searchpair_errors()
+  call assert_fails("call searchpair([0], 'middle', 'end', 'bW', 'skip', 99, 100)", 'E730: using List as a String')
+  call assert_fails("call searchpair('start', {-> 0}, 'end', 'bW', 'skip', 99, 100)", 'E729: using Funcref as a String')
+  call assert_fails("call searchpair('start', 'middle', {'one': 1}, 'bW', 'skip', 99, 100)", 'E731: using Dictionary as a String')
+  call assert_fails("call searchpair('start', 'middle', 'end', 'flags', 'skip', 99, 100)", 'E475: Invalid argument: flags')
+  call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 0, 99, 100)", 'E475: Invalid argument: 0')
+  call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 'func', -99, 100)", 'E475: Invalid argument: -99')
+  call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 'func', 99, -100)", 'E475: Invalid argument: -100')
+endfunc
+
 func Test_searchpair_skip()
     func Zero()
        return 0
@@ -311,8 +321,6 @@ func Test_searchpair_skip()
     3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', {-> 0}))
     3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', function('Zero')))
     3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', function('Partial', [0])))
-    " invalid argument
-    3 | call assert_equal(0, searchpair('{', '', '}', 'bWn', 0))
     bw!
 endfunc
 
index 95332ca246275c57c2855966a93011c17c32d2c0..06ed8ce24e6413b3e47f24fdb60302d63d2af436 100644 (file)
@@ -789,6 +789,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    112,
 /**/
     111,
 /**/