4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: Calling a function through a funcref, where the function deletes
12 the funcref, leads to an invalid memory access.
13 Solution: Make a copy of the function name. (Lech Lorens)
14 Files: src/eval.c, src/testdir/test34.in, src/testdir/test34.ok
17 *** ../vim-7.2.439/src/eval.c 2010-05-16 13:26:19.000000000 +0200
18 --- src/eval.c 2010-05-28 22:01:07.000000000 +0200
21 static int find_internal_func __ARGS((char_u *name));
22 static char_u *deref_func_name __ARGS((char_u *name, int *lenp));
23 static int get_func_tv __ARGS((char_u *name, int len, typval_T *rettv, char_u **arg, linenr_T firstline, linenr_T lastline, int *doesrange, int evaluate, dict_T *selfdict));
24 ! static int call_func __ARGS((char_u *name, int len, typval_T *rettv, int argcount, typval_T *argvars, linenr_T firstline, linenr_T lastline, int *doesrange, int evaluate, dict_T *selfdict));
25 static void emsg_funcname __ARGS((char *ermsg, char_u *name));
26 static int non_zero_arg __ARGS((typval_T *argvars));
29 static int find_internal_func __ARGS((char_u *name));
30 static char_u *deref_func_name __ARGS((char_u *name, int *lenp));
31 static int get_func_tv __ARGS((char_u *name, int len, typval_T *rettv, char_u **arg, linenr_T firstline, linenr_T lastline, int *doesrange, int evaluate, dict_T *selfdict));
32 ! static int call_func __ARGS((char_u *func_name, int len, typval_T *rettv, int argcount, typval_T *argvars, linenr_T firstline, linenr_T lastline, int *doesrange, int evaluate, dict_T *selfdict));
33 static void emsg_funcname __ARGS((char *ermsg, char_u *name));
34 static int non_zero_arg __ARGS((typval_T *argvars));
38 * Also returns OK when an error was encountered while executing the function.
41 ! call_func(name, len, rettv, argcount, argvars, firstline, lastline,
42 doesrange, evaluate, selfdict)
43 ! char_u *name; /* name of the function */
44 int len; /* length of "name" */
45 typval_T *rettv; /* return value goes here */
46 int argcount; /* number of "argvars" */
48 * Also returns OK when an error was encountered while executing the function.
51 ! call_func(func_name, len, rettv, argcount, argvars, firstline, lastline,
52 doesrange, evaluate, selfdict)
53 ! char_u *func_name; /* name of the function */
54 int len; /* length of "name" */
55 typval_T *rettv; /* return value goes here */
56 int argcount; /* number of "argvars" */
64 char_u fname_buf[FLEN_FIXED + 1];
68 * In a script change <SID>name() and s:name() to K_SNR 123_name().
69 * Change <SNR>123_name() to K_SNR 123_name().
70 * Use fname_buf[] when it fits, otherwise allocate memory (slow).
74 llen = eval_fname_script(name);
82 char_u fname_buf[FLEN_FIXED + 1];
86 + /* Make a copy of the name, if it comes from a funcref variable it could
87 + * be changed or deleted in the called function. */
88 + name = vim_strnsave(func_name, len);
93 * In a script change <SID>name() and s:name() to K_SNR 123_name().
94 * Change <SNR>123_name() to K_SNR 123_name().
95 * Use fname_buf[] when it fits, otherwise allocate memory (slow).
97 llen = eval_fname_script(name);
106 if (fname != name && fname != fname_buf)
115 if (fname != name && fname != fname_buf)
121 *** ../vim-7.2.439/src/testdir/test34.in 2007-09-25 17:59:15.000000000 +0200
122 --- src/testdir/test34.in 2010-05-28 21:54:36.000000000 +0200
129 + :func FuncWithRef(a)
133 + :let g:FuncRef=function("FuncWithRef")
135 :inoremap <expr> ( ListItem()
136 :inoremap <expr> [ ListReset()
141 \12=Compute(45, 5, "retval")
147 *** ../vim-7.2.439/src/testdir/test34.ok 2006-04-30 20:49:40.000000000 +0200
148 --- src/testdir/test34.ok 2010-05-28 21:56:03.000000000 +0200
151 ! xxx4asdf fail nop ok 9
156 ! xxx4asdf fail nop ok 9 333
160 *** ../vim-7.2.439/src/version.c 2010-05-28 21:31:51.000000000 +0200
161 --- src/version.c 2010-05-28 22:03:30.000000000 +0200
165 { /* Add new patch number below this line */
171 Nobody will ever need more than 640 kB RAM.
173 Windows 98 requires 16 MB RAM.
175 Logical conclusion: Nobody will ever need Windows 98.
177 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
178 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
179 \\\ download, build and distribute -- http://www.A-A-P.org ///
180 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///