patch 8.2.4541: Crash in debugger when a variable is not available v8.2.4541
authorBram Moolenaar <Bram@vim.org>
Thu, 10 Mar 2022 20:47:43 +0000 (20:47 +0000)
committerBram Moolenaar <Bram@vim.org>
Thu, 10 Mar 2022 20:47:43 +0000 (20:47 +0000)
Problem:    Crash in debugger when a variable is not available in the current
            block.
Solution:   Check for a NULL name. (closes #9926)

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

index c05f4e1e472ae0d985b9191880776b33e75ad401..1856f8db4a00f94bbdf3695ecc708ac5829bf162 100644 (file)
@@ -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 *')
index 29477906041cb92240c807545ec07e7454e0974c..122ba03e41027baf6163789a82cf8da4926cf029 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4541,
 /**/
     4540,
 /**/
index d908e64314ca5ed82518f3882ec2ba7f466fdef5..2cf7e46ed9cbb27abd9787d49ed28144d3a814bd 100644 (file)
@@ -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);
     }