summaryrefslogtreecommitdiffstats
path: root/src/evalvars.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-04-13 17:52:26 +0200
committerChristian Brabandt <cb@256bit.org>2024-04-13 17:52:26 +0200
commit1f5175d9af3d3f37e19f23e0e6f84caec47390f2 (patch)
tree2f1e6a3bdb9378b763d9990a6375fe1678cd8eac /src/evalvars.c
parente74cad3321ce1dcefc1fc64f617511275b6cd930 (diff)
patch 9.1.0313: Crash when using heredoc with comment in command blockv9.1.0313
Problem: Crash when using heredoc with comment in command block. Solution: Handle a newline more like the end of the line, fix coverity warning (zeertzjq). closes: #14535 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'src/evalvars.c')
-rw-r--r--src/evalvars.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/evalvars.c b/src/evalvars.c
index 62728ed8ab..d4dd0add2a 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -781,8 +781,15 @@ heredoc_get(exarg_T *eap, char_u *cmd, int script_get, int vim9compile)
int count = 0;
int heredoc_in_string = FALSE;
char_u *line_arg = NULL;
+ char_u *nl_ptr = vim_strchr(cmd, '\n');
- if (eap->ea_getline == NULL && vim_strchr(cmd, '\n') == NULL)
+ if (nl_ptr != NULL)
+ {
+ heredoc_in_string = TRUE;
+ line_arg = nl_ptr + 1;
+ *nl_ptr = NUL;
+ }
+ else if (eap->ea_getline == NULL)
{
emsg(_(e_cannot_use_heredoc_here));
return NULL;
@@ -826,14 +833,8 @@ heredoc_get(exarg_T *eap, char_u *cmd, int script_get, int vim9compile)
if (*cmd != NUL && *cmd != comment_char)
{
marker = skipwhite(cmd);
- p = skiptowhite_or_nl(marker);
- if (*p == NL)
- {
- // heredoc in a string
- line_arg = p + 1;
- heredoc_in_string = TRUE;
- }
- else if (*skipwhite(p) != NUL && *skipwhite(p) != comment_char)
+ p = skiptowhite(marker);
+ if (*skipwhite(p) != NUL && *skipwhite(p) != comment_char)
{
semsg(_(e_trailing_characters_str), p);
return NULL;