diff src/vim9compile.c @ 30815:90a257beac7a v9.0.0742

patch 9.0.0742: reading past end of the line when compiling a function Commit: https://github.com/vim/vim/commit/3558afe9e9e904cabb8475392d859f2d2fc21041 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Oct 13 16:12:57 2022 +0100 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.
author Bram Moolenaar <Bram@vim.org>
date Thu, 13 Oct 2022 17:15:05 +0200
parents 9d2c4d49b006
children 3e8aed429cc5
line wrap: on
line diff
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -1284,6 +1284,19 @@ vim9_declare_error(char_u *name)
 }
 
 /*
+ * 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 @@ get_var_dest(
     }
     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 @@ compile_lhs(
     // "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 "$"