Vim crashes with SEGV when executing :py vim.bindeval("matchstr('', 'x')").

49 views
Skip to first unread message

Yukihiro Nakadaira

unread,
Oct 5, 2012, 7:06:16 AM10/5/12
to vim...@googlegroups.com
Vim crashes with SEGV when executing :py vim.bindeval("matchstr('', 'x')").
And vim.eval("matchstr('', 'x')") returns None.

The following patch fix this problem.
Please check it.


diff -r 61a7c3f01088 src/if_py_both.h
--- a/src/if_py_both.h Wed Oct 03 21:48:44 2012 +0200
+++ b/src/if_py_both.h Thu Oct 04 20:44:08 2012 +0900
@@ -351,7 +351,10 @@

if (our_tv->v_type == VAR_STRING)
{
- result = Py_BuildValue("s", our_tv->vval.v_string);
+ if (our_tv->vval.v_string == NULL)
+ result = Py_BuildValue("s", "");
+ else
+ result = Py_BuildValue("s", our_tv->vval.v_string);
}
else if (our_tv->v_type == VAR_NUMBER)
{
@@ -2751,7 +2754,10 @@
switch (tv->v_type)
{
case VAR_STRING:
- return PyBytes_FromString((char *) tv->vval.v_string);
+ if (tv->vval.v_string == NULL)
+ return PyBytes_FromString("");
+ else
+ return PyBytes_FromString((char *) tv->vval.v_string);
case VAR_NUMBER:
return PyLong_FromLong((long) tv->vval.v_number);
#ifdef FEAT_FLOAT


--
Yukihiro Nakadaira - yukihiro....@gmail.com

Bram Moolenaar

unread,
Oct 5, 2012, 3:11:06 PM10/5/12
to Yukihiro Nakadaira, vim...@googlegroups.com

Yukihiro Nakadaira wrote:

> Vim crashes with SEGV when executing :py vim.bindeval("matchstr('', 'x')").
> And vim.eval("matchstr('', 'x')") returns None.
>
> The following patch fix this problem.
> Please check it.

Thanks, I'll include it. I suppose we should also check for VAR_FUNC.


--
If you only have a hammer, you tend to see every problem as a nail.
If you only have MS-Windows, you tend to solve every problem by rebooting.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Yukihiro Nakadaira

unread,
Oct 11, 2012, 10:35:35 AM10/11/12
to Bram Moolenaar, vim...@googlegroups.com
On Sat, Oct 6, 2012 at 4:11 AM, Bram Moolenaar <Br...@moolenaar.net> wrote:
>
> Yukihiro Nakadaira wrote:
>
>> Vim crashes with SEGV when executing :py vim.bindeval("matchstr('', 'x')").
>> And vim.eval("matchstr('', 'x')") returns None.
>>
>> The following patch fix this problem.
>> Please check it.
>
> Thanks, I'll include it. I suppose we should also check for VAR_FUNC.

Thank you for including it.
Additionally if_mzsch.c and if_lua.c have same code.
Please check and include this.
I didn't do test for if_mzsch.c.

diff -r aa51675adf7e src/if_lua.c
--- a/src/if_lua.c Fri Oct 05 22:26:30 2012 +0200
+++ b/src/if_lua.c Thu Oct 11 23:26:25 2012 +0900
@@ -464,7 +464,8 @@
switch (tv->v_type)
{
case VAR_STRING:
- lua_pushstring(L, (char *) tv->vval.v_string);
+ lua_pushstring(L, tv->vval.v_string == NULL
+ ? "" : (char *)tv->vval.v_string);
break;
case VAR_NUMBER:
lua_pushinteger(L, (int) tv->vval.v_number);
diff -r aa51675adf7e src/if_mzsch.c
--- a/src/if_mzsch.c Fri Oct 05 22:26:30 2012 +0200
+++ b/src/if_mzsch.c Thu Oct 11 23:26:25 2012 +0900
@@ -2649,7 +2649,8 @@
new_value = FALSE;
else if (vim_value->v_type == VAR_STRING)
{
- result = scheme_make_string((char *)vim_value->vval.v_string);
+ result = scheme_make_string(vim_value->vval.v_string == NULL
+ ? "" : (char *)vim_value->vval.v_string);
MZ_GC_CHECK();
}
else if (vim_value->v_type == VAR_NUMBER)

Bram Moolenaar

unread,
Oct 11, 2012, 10:54:18 PM10/11/12
to Yukihiro Nakadaira, vim...@googlegroups.com

Yukihiro Nakadaira wrote:

> >> Vim crashes with SEGV when executing :py vim.bindeval("matchstr('', 'x')").
> >> And vim.eval("matchstr('', 'x')") returns None.
> >>
> >> The following patch fix this problem.
> >> Please check it.
> >
> > Thanks, I'll include it. I suppose we should also check for VAR_FUNC.
>
> Thank you for including it.
> Additionally if_mzsch.c and if_lua.c have same code.
> Please check and include this.
> I didn't do test for if_mzsch.c.

Thanks, I'll include this soon.


--
To keep milk from turning sour: Keep it in the cow.
Reply all
Reply to author
Forward
0 new messages