]> granicus.if.org Git - vim/commitdiff
patch 9.0.1370: crash when using a NULL object v9.0.1370
authorBram Moolenaar <Bram@vim.org>
Thu, 2 Mar 2023 17:38:33 +0000 (17:38 +0000)
committerBram Moolenaar <Bram@vim.org>
Thu, 2 Mar 2023 17:38:33 +0000 (17:38 +0000)
Problem:    Crash when using a NULL object. (Ernie Rael)
Solution:   Check for NULL and give an error message. (closes #12083)

src/testdir/test_vim9_class.vim
src/version.c
src/vim9execute.c

index 3bb289b47e26da02aab0d3556bda33f4d2641445..c228f2642ba3c0f03ef75200f094aea3cce27e39 100644 (file)
@@ -235,6 +235,24 @@ def Test_object_not_set()
   END
   v9.CheckScriptFailure(lines, 'E1360:')
 
+  lines =<< trim END
+      vim9script
+
+      class Class
+          this.id: string
+          def Method1()
+              echo 'Method1' .. this.id
+          enddef
+      endclass
+
+      var obj: Class
+      def Func()
+          obj.Method1()
+      enddef
+      Func()
+  END
+  v9.CheckScriptFailure(lines, 'E1360:')
+
   lines =<< trim END
       vim9script
 
index 6aa63ef672e342d735a23fbd4ad13d7239d73539..857c1394ca6f845bc1609589a83d90e9fd5e87bf 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1370,
 /**/
     1369,
 /**/
index bc4a1fcc08b8819945d5eacd1d1add60d4d8a8b3..f8ce10170f5bb35053a2737c10258297bc8fa6b2 100644 (file)
@@ -5321,6 +5321,13 @@ exec_instructions(ectx_T *ectx)
                    }
 
                    object_T *obj = tv->vval.v_object;
+                   if (obj == NULL)
+                   {
+                       SOURCING_LNUM = iptr->isn_lnum;
+                       emsg(_(e_using_null_object));
+                       goto on_error;
+                   }
+
                    int idx;
                    if (iptr->isn_type == ISN_GET_OBJ_MEMBER)
                        idx = iptr->isn_arg.number;