aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-04-14 05:03:49 +0800
committerzeertzjq <zeertzjq@outlook.com>2024-04-14 05:06:50 +0800
commite81fe387d6291e5643a97a61e6d05b48aaeab2a1 (patch)
treeff7a5e6193170512cbbe385866239d901dc5ac40 /src
parent617a3851426434bc22d82fe7574ba8f0455c0dcd (diff)
downloadrneovim-e81fe387d6291e5643a97a61e6d05b48aaeab2a1.tar.gz
rneovim-e81fe387d6291e5643a97a61e6d05b48aaeab2a1.tar.bz2
rneovim-e81fe387d6291e5643a97a61e6d05b48aaeab2a1.zip
vim-patch:9.1.0313: Crash when using heredoc with comment in command block
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: vim/vim#14535 https://github.com/vim/vim/commit/1f5175d9af3d3f37e19f23e0e6f84caec47390f2
Diffstat (limited to 'src')
-rw-r--r--src/nvim/charset.c14
-rw-r--r--src/nvim/eval/vars.c19
2 files changed, 10 insertions, 23 deletions
diff --git a/src/nvim/charset.c b/src/nvim/charset.c
index 59932b2eb0..c611d4cfd6 100644
--- a/src/nvim/charset.c
+++ b/src/nvim/charset.c
@@ -1045,20 +1045,6 @@ char *skiptowhite(const char *p)
return (char *)p;
}
-/// Skip over text until ' ' or '\t' or newline or NUL
-///
-/// @param[in] p Text to skip over.
-///
-/// @return Pointer to the next whitespace or newline or NUL character.
-char *skiptowhite_or_nl(const char *p)
- FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE
-{
- while (*p != ' ' && *p != '\t' && *p != NL && *p != NUL) {
- p++;
- }
- return (char *)p;
-}
-
/// skiptowhite_esc: Like skiptowhite(), but also skip escaped chars
///
/// @param p
diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c
index 70ecb76deb..37199cd95d 100644
--- a/src/nvim/eval/vars.c
+++ b/src/nvim/eval/vars.c
@@ -179,8 +179,15 @@ list_T *heredoc_get(exarg_T *eap, char *cmd, bool script_get)
int text_indent_len = 0;
char *text_indent = NULL;
char dot[] = ".";
+ bool heredoc_in_string = false;
+ char *line_arg = NULL;
+ char *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;
}
@@ -217,17 +224,11 @@ list_T *heredoc_get(exarg_T *eap, char *cmd, bool script_get)
}
const char comment_char = '"';
- bool heredoc_in_string = false;
- char *line_arg = NULL;
// The marker is the next word.
if (*cmd != NUL && *cmd != comment_char) {
marker = skipwhite(cmd);
- char *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) {
+ char *p = skiptowhite(marker);
+ if (*skipwhite(p) != NUL && *skipwhite(p) != comment_char) {
semsg(_(e_trailing_arg), p);
return NULL;
}