diff src/vim9compile.c @ 24444:b5fbe8280853 v8.2.2762

patch 8.2.2762: Vim9: function line truncated when compiling Commit: https://github.com/vim/vim/commit/f62d73933af7830301989eb8162ce94a80e61fbf Author: Bram Moolenaar <Bram@vim.org> Date: Wed Apr 14 12:40:00 2021 +0200 patch 8.2.2762: Vim9: function line truncated when compiling Problem: Vim9: function line truncated when compiling. Solution: Copy the line before processing it. (closes https://github.com/vim/vim/issues/8101)
author Bram Moolenaar <Bram@vim.org>
date Wed, 14 Apr 2021 12:45:05 +0200
parents d2f9bdd938fa
children 385ccfd6b6de
line wrap: on
line diff
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -8486,6 +8486,7 @@ compile_def_function(
 	cctx_T	    *outer_cctx)
 {
     char_u	*line = NULL;
+    char_u	*line_to_free = NULL;
     char_u	*p;
     char	*errormsg = NULL;	// error message
     cctx_T	cctx;
@@ -8647,6 +8648,14 @@ compile_def_function(
 #endif
 		break;
 	    }
+	    // Make a copy, splitting off nextcmd and removing trailing spaces
+	    // may change it.
+	    if (line != NULL)
+	    {
+		line = vim_strsave(line);
+		vim_free(line_to_free);
+		line_to_free = line;
+	    }
 	}
 
 	CLEAR_FIELD(ea);
@@ -9095,6 +9104,7 @@ erret:
     if (do_estack_push)
 	estack_pop();
 
+    vim_free(line_to_free);
     free_imported(&cctx);
     free_locals(&cctx);
     ga_clear(&cctx.ctx_type_stack);