changeset 35493:047733a6b42b v9.1.0513

patch 9.1.0513: Vim9: segfault with object comparison Commit: https://github.com/vim/vim/commit/f0e691442005c12a7c35746048f0942f44e23a4c Author: Ernie Rael <errael@raelity.com> Date: Sat Jun 22 11:12:00 2024 +0200 patch 9.1.0513: Vim9: segfault with object comparison Problem: Vim9: segfault with object comparisons Solution: increment recusive_cnt before calling typval_compare_object() (Ernie Rael) closes: #15073 Signed-off-by: Ernie Rael <errael@raelity.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Sat, 22 Jun 2024 11:15:07 +0200
parents efb3bd0f637d
children f284ed281150
files src/testdir/test_vim9_class.vim src/typval.c src/version.c
diffstat 3 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_vim9_class.vim
+++ b/src/testdir/test_vim9_class.vim
@@ -10486,6 +10486,24 @@ def Test_Ref_Class_Within_Same_Class()
   v9.CheckScriptFailure(lines, 'E1347: Not a valid interface: A', 3)
 enddef
 
+" Test for comparing a class referencing itself
+def Test_Object_Compare_With_Recursive_Class_Ref()
+  var lines =<< trim END
+    vim9script
+
+    class C
+    public var nest: C
+    endclass
+
+    var o1 = C.new()
+    o1.nest = o1
+
+    var result = o1 == o1
+    assert_equal(true, result)
+  END
+  v9.CheckScriptSuccess(lines)
+enddef
+
 " Test for using a compound operator from a lambda function in an object method
 def Test_compound_op_in_objmethod_lambda()
   # Test using the "+=" operator
--- a/src/typval.c
+++ b/src/typval.c
@@ -2114,7 +2114,9 @@ tv_equal(
 	    return tv1->vval.v_class == tv2->vval.v_class;
 
 	case VAR_OBJECT:
+	    ++recursive_cnt;
 	    (void)typval_compare_object(tv1, tv2, EXPR_EQUAL, ic, &r);
+	    --recursive_cnt;
 	    return r;
 
 	case VAR_PARTIAL:
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    513,
+/**/
     512,
 /**/
     511,