Hello,

I received a bug report from machakann and ikunikun.

Vim 7.4.179 on Fedora19 (64bit)
(Vim's required config: --enable-multibyte)

How to reproduce.
1.
  $ vim -N -u NONE --cmd "set enc=utf-8"

1-1.
  :echo match('abc', '$', 0, 2)  " Should return -1
  3

1-2.
  :echo match('abc', '$', 0, 12345678)  " Should return -1
  3  " And very slowly. (about 7sec)

2.
  $ vim -N -u NONE --cmd "set enc=latin1"

2-1.
  :echo match('abc', '$', 0, 2)  " Should return -1
  4   " 

2-2.
  :echo match('abc', '$', 0, 12345678)  " Should return -1
  Vim: Caught deadly signal SEGV
  Vim: Finished.
  Segmentation fault

I wrote a patch. (including test)
Please check it.

Best Regards,
Hirohito Higashi

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
diff -r 277885c9c344 src/eval.c
--- a/src/eval.c	Wed Feb 12 22:08:49 2014 +0100
+++ b/src/eval.c	Sun Feb 16 15:55:50 2014 +0900
@@ -13905,6 +13905,7 @@
     int		type;
 {
     char_u	*str = NULL;
+    int 	len = 0;
     char_u	*expr = NULL;
     char_u	*pat;
     regmatch_T	regmatch;
@@ -13944,7 +13945,10 @@
 	li = l->lv_first;
     }
     else
+    {
 	expr = str = get_tv_string(&argvars[0]);
+	len = (int)STRLEN(str);
+    }
 
     pat = get_tv_string_buf_chk(&argvars[1], patbuf);
     if (pat == NULL)
@@ -13968,7 +13972,7 @@
 	{
 	    if (start < 0)
 		start = 0;
-	    if (start > (long)STRLEN(str))
+	    if (start > (long)len)
 		goto theend;
 	    /* When "count" argument is there ignore matches before "start",
 	     * otherwise skip part of the string.  Differs when pattern is "^"
@@ -13976,7 +13980,10 @@
 	    if (argvars[3].v_type != VAR_UNKNOWN)
 		startcol = start;
 	    else
+	    {
 		str += start;
+		len -= start;
+	    }
 	}
 
 	if (argvars[3].v_type != VAR_UNKNOWN)
@@ -14026,6 +14033,12 @@
 #else
 		startcol = (colnr_T)(regmatch.startp[0] + 1 - str);
 #endif
+		if (startcol > (colnr_T)len
+					|| str + startcol <= regmatch.startp[0])
+		{
+		    match = FALSE;
+		    break;
+		}
 	    }
 	}
 
diff -r 277885c9c344 src/testdir/test53.in
--- a/src/testdir/test53.in	Wed Feb 12 22:08:49 2014 +0100
+++ b/src/testdir/test53.in	Sun Feb 16 15:55:50 2014 +0900
@@ -28,6 +28,28 @@
 :put =matchstr(\"abcd\", \".\", 0, -1) " a
 :put =match(\"abcd\", \".\", 0, 5) " -1
 :put =match(\"abcd\", \".\", 0, -1) " 0
+:put =match('abc', '.', 0, 1) " 0
+:put =match('abc', '.', 0, 2) " 1
+:put =match('abc', '.', 0, 3) " 2
+:put =match('abc', '.', 0, 4) " -1
+:put =match('abc', '.', 1, 1) " 1
+:put =match('abc', '.', 2, 1) " 2
+:put =match('abc', '.', 3, 1) " -1
+:put =match('abc', '$', 0, 1) " 3
+:put =match('abc', '$', 0, 2) " -1
+:put =match('abc', '$', 1, 1) " 3
+:put =match('abc', '$', 2, 1) " 3
+:put =match('abc', '$', 3, 1) " 3
+:put =match('abc', '$', 4, 1) " -1
+:put =match('abc', '\zs', 0, 1) " 0
+:put =match('abc', '\zs', 0, 2) " 1
+:put =match('abc', '\zs', 0, 3) " 2
+:put =match('abc', '\zs', 0, 4) " 3
+:put =match('abc', '\zs', 0, 5) " -1
+:put =match('abc', '\zs', 1, 1) " 1
+:put =match('abc', '\zs', 2, 1) " 2
+:put =match('abc', '\zs', 3, 1) " 3
+:put =match('abc', '\zs', 4, 1) " -1
 /^foobar
 gncsearchmatch?one\_s*two\_s
 :1
diff -r 277885c9c344 src/testdir/test53.ok
--- a/src/testdir/test53.ok	Wed Feb 12 22:08:49 2014 +0100
+++ b/src/testdir/test53.ok	Sun Feb 16 15:55:50 2014 +0900
@@ -18,6 +18,28 @@
 a
 -1
 0
+0
+1
+2
+-1
+1
+2
+-1
+3
+-1
+3
+3
+3
+-1
+0
+1
+2
+3
+-1
+1
+2
+3
+-1
 SEARCH:
 searchmatch
 abcdx |  | abcdx

Raspunde prin e-mail lui