Crash when extend(o, o)

62 views
Skip to first unread message

mattn

unread,
May 2, 2012, 2:01:57 PM5/2/12
to vim...@googlegroups.com
When passing same Dictionary/List to expand(), it breaks reference counter.

let o = {"a":{"b":"B"}}
call extend(o, o)
echo o.a.b <= crash

https://gist.github.com/2578755

Please check and include.

diff -r 8201108e9cf0 src/eval.c
--- a/src/eval.c Tue May 01 21:14:34 2012 +0200
+++ b/src/eval.c Thu May 03 03:00:30 2012 +0900
@@ -10110,7 +10110,7 @@
l1 = argvars[0].vval.v_list;
l2 = argvars[1].vval.v_list;
if (l1 != NULL && !tv_check_lock(l1->lv_lock, (char_u *)_(arg_errmsg))
- && l2 != NULL)
+ && l2 != NULL && l1 != l2)
{
if (argvars[2].v_type != VAR_UNKNOWN)
{
@@ -10149,7 +10149,7 @@
d1 = argvars[0].vval.v_dict;
d2 = argvars[1].vval.v_dict;
if (d1 != NULL && !tv_check_lock(d1->dv_lock, (char_u *)_(arg_errmsg))
- && d2 != NULL)
+ && d2 != NULL && d1 != d2)
{
/* Check the third argument. */
if (argvars[2].v_type != VAR_UNKNOWN)
@@ -10191,7 +10191,7 @@
EMSG2(_("E737: Key already exists: %s"), hi2->hi_key);
break;
}
- else if (*action == 'f')
+ else if (*action == 'f' && HI2DI(hi2) != di1)
{
clear_tv(&di1->di_tv);
copy_tv(&HI2DI(hi2)->di_tv, &di1->di_tv);

Bram Moolenaar

unread,
May 2, 2012, 2:55:50 PM5/2/12
to mattn, vim...@googlegroups.com

Yasohiro Matsumoto wrote:

> When passing same Dictionary/List to expand(), it breaks reference counter.
>
> let o = {"a":{"b":"B"}}
> call extend(o, o)
> echo o.a.b <= crash
>
> https://gist.github.com/2578755
>
> Please check and include.

Thanks for the fix! Can you also write a test for this?

--
Snoring is prohibited unless all bedroom windows are closed and securely
locked.
[real standing law in Massachusetts, United States of America]

/// 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 ///

h_east

unread,
May 5, 2012, 10:59:03 AM5/5/12
to vim...@googlegroups.com
2012/5/3 (Thu) 3:55:50 UTC+9 Bram Moolenaar:

> Yasohiro Matsumoto wrote:
>
> > When passing same Dictionary/List to expand(), it breaks reference counter.
> >
> > let o = {"a":{"b":"B"}}
> > call extend(o, o)
> > echo o.a.b <= crash
> >
> > https://gist.github.com/2578755
> >
> > Please check and include.
>
> Thanks for the fix! Can you also write a test for this?

Hi Bram,

Patch modified and test added.
eval.c patch author is Thinca.
test patch author is me.
(I have got consent from Yasuhiro Matsumoto.)

Please check.

Regards,
--
Hirohito Higashi

patch_extend_bugfix.diff

mattn

unread,
May 5, 2012, 11:24:25 AM5/5/12
to vim...@googlegroups.com
Thanks Hirohito.

Bram, this original patch is writen by thinca. And tests above is writen by Hirohito.

Bram Moolenaar

unread,
May 6, 2012, 7:06:34 AM5/6/12
to h_east, vim...@googlegroups.com
Thanks! I will look into it soon.

--
Living on Earth includes an annual free trip around the Sun.
Reply all
Reply to author
Forward
0 new messages