summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2023-03-02 17:38:33 +0000
committerBram Moolenaar <Bram@vim.org>2023-03-02 17:38:33 +0000
commitc3f971f28989fde7d94b45957496fecd6e6f2177 (patch)
tree488b57a6d586fd99707993d382d4244ef8b9eccf
parentc6ff21e876af0e3ad59664dd0f69359c4b6e9f1d (diff)
patch 9.0.1370: crash when using a NULL objectv9.0.1370
Problem: Crash when using a NULL object. (Ernie Rael) Solution: Check for NULL and give an error message. (closes #12083)
-rw-r--r--src/testdir/test_vim9_class.vim18
-rw-r--r--src/version.c2
-rw-r--r--src/vim9execute.c7
3 files changed, 27 insertions, 0 deletions
diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim
index 3bb289b47e..c228f2642b 100644
--- a/src/testdir/test_vim9_class.vim
+++ b/src/testdir/test_vim9_class.vim
@@ -238,6 +238,24 @@ def Test_object_not_set()
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
+
class Background
this.background = 'dark'
endclass
diff --git a/src/version.c b/src/version.c
index 6aa63ef672..857c1394ca 100644
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1370,
+/**/
1369,
/**/
1368,
diff --git a/src/vim9execute.c b/src/vim9execute.c
index bc4a1fcc08..f8ce10170f 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -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;