patch 9.0.0742: reading past end of the line when compiling a function
Problem: Reading past end of the line when compiling a function with
errors.
Solution: Do not return an invalid pointer. Fix skipping redirection.
diff --git a/src/vim9compile.c b/src/vim9compile.c
index b3e1b83..73bfa6c 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -1284,6 +1284,19 @@
}
/*
+ * Return TRUE if "name" is a valid register to use.
+ * Return FALSE and give an error message if not.
+ */
+ static int
+valid_dest_reg(int name)
+{
+ if ((name == '@' || valid_yank_reg(name, FALSE)) && name != '.')
+ return TRUE;
+ emsg_invreg(name);
+ return FAIL;
+}
+
+/*
* For one assignment figure out the type of destination. Return it in "dest".
* When not recognized "dest" is not set.
* For an option "option_scope" is set.
@@ -1364,12 +1377,8 @@
}
else if (*name == '@')
{
- if (name[1] != '@'
- && (!valid_yank_reg(name[1], FALSE) || name[1] == '.'))
- {
- emsg_invreg(name[1]);
+ if (!valid_dest_reg(name[1]))
return FAIL;
- }
*dest = dest_reg;
*type = name[1] == '#' ? &t_number_or_string : &t_string;
}
@@ -1445,7 +1454,11 @@
// "var_end" is the end of the variable/option/etc. name.
lhs->lhs_dest_end = skip_var_one(var_start, FALSE);
if (*var_start == '@')
+ {
+ if (!valid_dest_reg(var_start[1]))
+ return FAIL;
var_end = var_start + 2;
+ }
else
{
// skip over the leading "&", "&l:", "&g:" and "$"