On 20-Oct-2010 Lech Lorens <[email protected]> wrote:
> OK, I can reproduce the crash. Do the following (vim-crash.vim
> attached):
> 
> $ vim -u NONE -S vim-crash.vim

Here's a patch fixing the problem and adding a proper test.

-- 
Cheers,
Lech

-- 
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
diff --git a/src/edit.c b/src/edit.c
index 04a17eb..599637a 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -3833,6 +3833,8 @@ expand_by_function(type, base)
     char_u	*args[2];
     char_u	*funcname;
     pos_T	pos;
+    win_T	*saveWin;
+    buf_T	*saveBuf;
 
     funcname = (type == CTRL_X_FUNCTION) ? curbuf->b_p_cfu : curbuf->b_p_ofu;
     if (*funcname == NUL)
@@ -3843,7 +3845,11 @@ expand_by_function(type, base)
     args[1] = base;
 
     pos = curwin->w_cursor;
+    saveWin = curwin;
+    saveBuf = curbuf;
     matchlist = call_func_retlist(funcname, 2, args, FALSE);
+    curbuf = saveBuf;
+    curwin = saveWin;
     curwin->w_cursor = pos;	/* restore the cursor position */
     if (matchlist == NULL)
 	return;
@@ -4994,6 +5000,8 @@ ins_complete(c)
 	    int		col;
 	    char_u	*funcname;
 	    pos_T	pos;
+	    win_T	*saveWin;
+	    buf_T	*saveBuf;
 
 	    /* Call 'completefunc' or 'omnifunc' and get pattern length as a
 	     * string */
@@ -5009,7 +5017,11 @@ ins_complete(c)
 	    args[0] = (char_u *)"1";
 	    args[1] = NULL;
 	    pos = curwin->w_cursor;
+	    saveWin = curwin;
+	    saveBuf = curbuf;
 	    col = call_func_retnr(funcname, 2, args, FALSE);
+	    curbuf = saveBuf;
+	    curwin = saveWin;
 	    curwin->w_cursor = pos;	/* restore the cursor position */
 
 	    if (col < 0)
diff --git a/src/testdir/Makefile b/src/testdir/Makefile
index bdc2c28..6f1726d 100644
--- a/src/testdir/Makefile
+++ b/src/testdir/Makefile
@@ -23,7 +23,8 @@ SCRIPTS = test1.out test2.out test3.out test4.out test5.out test6.out \
 		test54.out test55.out test56.out test57.out test58.out \
 		test59.out test60.out test61.out test62.out test63.out \
 		test64.out test65.out test66.out test67.out test68.out \
-		test69.out test70.out test71.out test72.out test73.out
+		test69.out test70.out test71.out test72.out test73.out \
+		test74.out
 
 SCRIPTS_GUI = test16.out
 
diff --git a/src/testdir/test74.in b/src/testdir/test74.in
new file mode 100644
index 0000000..3e2a683
--- /dev/null
+++ b/src/testdir/test74.in
@@ -0,0 +1,20 @@
+Tests for completefunc/omnifunc. vim: set ft=vim :
+
+STARTTEST
+:"Test what happens if the 'completefunc' changes
+:"the current window and buffer.
+:so small.vim
+:function! DummyComplete(findstart, base)
+:    if a:findstart
+:        return 0
+:    else
+:        wincmd n
+:        return ['abcdef', 'abcDEF']
+:    endif
+:endfunction
+:setlocal completefunc=DummyComplete
+GA:w test.out
+:qa!
+ENDTEST
+
+abc
diff --git a/src/testdir/test74.ok b/src/testdir/test74.ok
new file mode 100644
index 0000000..e3723ee
--- /dev/null
+++ b/src/testdir/test74.ok
@@ -0,0 +1,20 @@
+Tests for completefunc/omnifunc. vim: set ft=vim :
+
+STARTTEST
+:"Test what happens if the 'completefunc' changes
+:"the current window and buffer.
+:so small.vim
+:function! DummyComplete(findstart, base)
+:    if a:findstart
+:        return 0
+:    else
+:        wincmd n
+:        return ['abcdef', 'abcDEF']
+:    endif
+:endfunction
+:setlocal completefunc=DummyComplete
+GA:w test.out
+:qa!
+ENDTEST
+
+abcDEF

Raspunde prin e-mail lui