summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-03-10 20:47:43 +0000
committerBram Moolenaar <Bram@vim.org>2022-03-10 20:47:43 +0000
commite406ff87c86de9da2d02d0e5ebbbf5c5eac051a6 (patch)
tree9a4e88b915178211c311d1bef0bc88c1eb99ec69
parent1b1df95f1a84cbc362e32f676f1e135aa2e7fc3c (diff)
downloadvim-git-e406ff87c86de9da2d02d0e5ebbbf5c5eac051a6.tar.gz
patch 8.2.4541: Crash in debugger when a variable is not availablev8.2.4541
Problem: Crash in debugger when a variable is not available in the current block. Solution: Check for a NULL name. (closes #9926)
-rw-r--r--src/testdir/test_debugger.vim15
-rw-r--r--src/version.c2
-rw-r--r--src/vim9execute.c5
3 files changed, 21 insertions, 1 deletions
diff --git a/src/testdir/test_debugger.vim b/src/testdir/test_debugger.vim
index c05f4e1e4..1856f8db4 100644
--- a/src/testdir/test_debugger.vim
+++ b/src/testdir/test_debugger.vim
@@ -73,6 +73,13 @@ func Test_Debugger()
endtry
return var1
endfunc
+ def Vim9Func()
+ for cmd in ['confirm', 'xxxxxxx']
+ for _ in [1, 2]
+ echo cmd
+ endfor
+ endfor
+ enddef
END
call writefile(lines, 'Xtest.vim')
@@ -298,6 +305,14 @@ func Test_Debugger()
\ 'line 5: catch'])
call RunDbgCmd(buf, 'c')
+ " Test showing local variable in :def function
+ call RunDbgCmd(buf, ':breakadd func 2 Vim9Func')
+ call RunDbgCmd(buf, ':call Vim9Func()', ['line 2: for _ in [1, 2]'])
+ call RunDbgCmd(buf, 'next', ['line 2: for _ in [1, 2]'])
+ call RunDbgCmd(buf, 'echo cmd', ['confirm'])
+ call RunDbgCmd(buf, 'breakdel *')
+ call RunDbgCmd(buf, 'cont')
+
" Test for :quit
call RunDbgCmd(buf, ':debug echo Foo()')
call RunDbgCmd(buf, 'breakdel *')
diff --git a/src/version.c b/src/version.c
index 294779060..122ba03e4 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 4541,
+/**/
4540,
/**/
4539,
diff --git a/src/vim9execute.c b/src/vim9execute.c
index d908e6431..2cf7e46ed 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -1622,7 +1622,10 @@ lookup_debug_var(char_u *name)
// Go through the local variable names, from last to first.
for (idx = debug_var_count - 1; idx >= 0; --idx)
{
- if (STRCMP(((char_u **)dfunc->df_var_names.ga_data)[idx], name) == 0)
+ char_u *varname = ((char_u **)dfunc->df_var_names.ga_data)[idx];
+
+ // the variable name may be NULL when not available in this block
+ if (varname != NULL && STRCMP(varname, name) == 0)
return STACK_TV_VAR(idx);
}