patch 8.2.4541: Crash in debugger when a variable is not available
Problem: Crash in debugger when a variable is not available in the current
block.
Solution: Check for a NULL name. (closes #9926)
diff --git a/src/vim9execute.c b/src/vim9execute.c
index d908e64..2cf7e46 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -1622,7 +1622,10 @@
// 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);
}