]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1087: Vim9: import with extends may crash v9.1.1087
authorHirohito Higashi <h.east.727@gmail.com>
Sun, 9 Feb 2025 15:41:23 +0000 (16:41 +0100)
committerChristian Brabandt <cb@256bit.org>
Sun, 9 Feb 2025 15:41:23 +0000 (16:41 +0100)
Problem:  Vim9: import with extends may crash
Solution: check otv for being NULL before trying to access it
          (Hirohito Higashi)

closes: #16601

Signed-off-by: Hirohito Higashi <h.east.727@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/testdir/test_vim9_import.vim
src/version.c
src/vim9execute.c

index ff81f4a53d4166c0ecd0c6507939173c03f4bfe5..c8dfa1e7311d6499bd9cdaa53c8283579b0e5ed1 100644 (file)
@@ -3420,4 +3420,42 @@ def Test_imported_class_as_def_func_rettype()
   v9.CheckScriptSuccess(lines)
 enddef
 
+" Test for don't crash when using a combination of import and class extends
+def Test_vim9_import_and_class_extends()
+  var lines =<< trim END
+    vim9script
+    import './cccc.vim'
+    export class Property extends cccc.Run
+      public var value: string
+      def new(this.value)
+      cccc.Run.value2 = this.value
+    enddef
+    endclass
+  END
+  writefile(lines, './aaaa.vim', 'D')
+
+  lines =<< trim END
+    vim9script
+    export class Run
+      public var value2: string
+      def new(this.value)
+      enddef
+    endclass
+  END
+  writefile(lines, './cccc.vim', 'D')
+
+  lines =<< trim END
+    vim9script
+    import './aaaa.vim'
+    class View
+      var content = aaaa.Property.new('')
+    endclass
+
+    var myView = View.new('This should be ok')
+    assert_equal('This should be ok', myView.content.value)
+  END
+  # TODO: The root cause will be identified later.
+  v9.CheckScriptFailure(lines, 'E1099: Unknown error while executing new', 7)
+enddef
+
 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
index b8f783e96694f3dd8a02e73f50c67aac9bed232e..01ce8737b8eb0e7e62c519dd20d7d4b8a7c55383 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1087,
 /**/
     1086,
 /**/
index c7f0e673b22845c56920e080c1f5828cd874426c..50220006bf6bc099078039e02626aec358e9b9b1 100644 (file)
@@ -2461,8 +2461,14 @@ execute_storeindex(isn_T *iptr, ectx_T *ectx)
                otv = class->class_members_tv;
            }
 
-           clear_tv(&otv[lidx]);
-           otv[lidx] = *tv;
+           if (otv != NULL)
+           {
+               clear_tv(&otv[lidx]);
+               otv[lidx] = *tv;
+           }
+           else
+               status = FAIL;
+
        }
        else
        {