aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/quickfix.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-11-19 10:57:06 +0800
committerGitHub <noreply@github.com>2022-11-19 10:57:06 +0800
commitf2b30b4d62b97da6ae1b4dd7c4e5730fc5bc95f7 (patch)
treef2a2cc60cabd9d718eed72faeeaa5871cd189ad2 /src/nvim/quickfix.c
parentdb407010facc55c19b5ebdf881225ac39cb29d01 (diff)
downloadrneovim-f2b30b4d62b97da6ae1b4dd7c4e5730fc5bc95f7.tar.gz
rneovim-f2b30b4d62b97da6ae1b4dd7c4e5730fc5bc95f7.tar.bz2
rneovim-f2b30b4d62b97da6ae1b4dd7c4e5730fc5bc95f7.zip
vim-patch:8.2.0260: several lines of code are duplicated (#21108)
Problem: Several lines of code are duplicated. Solution: Move duplicated code to a function. (Yegappan Lakshmanan, closes vim/vim#5330) https://github.com/vim/vim/commit/f4140488c72cad4dbf5449dba099cfa7de7bbb22 Using sizeof seems better than ARRAY_SIZE for vim_snprintf().
Diffstat (limited to 'src/nvim/quickfix.c')
-rw-r--r--src/nvim/quickfix.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c
index 27a0842016..cadbab91f4 100644
--- a/src/nvim/quickfix.c
+++ b/src/nvim/quickfix.c
@@ -1338,9 +1338,9 @@ static int qf_parse_fmt_t(regmatch_T *rmp, int midx, qffields_T *fields)
return QF_OK;
}
-/// Parse the match for '%+' format pattern. The whole matching line is included
-/// in the error string. Return the matched line in "fields->errmsg".
-static void qf_parse_fmt_plus(const char *linebuf, size_t linelen, qffields_T *fields)
+/// Copy a non-error line into the error string. Return the matched line in
+/// "fields->errmsg".
+static int copy_nonerror_line(const char *linebuf, size_t linelen, qffields_T *fields)
FUNC_ATTR_NONNULL_ALL
{
if (linelen >= fields->errmsglen) {
@@ -1348,7 +1348,10 @@ static void qf_parse_fmt_plus(const char *linebuf, size_t linelen, qffields_T *f
fields->errmsg = xrealloc(fields->errmsg, linelen + 1);
fields->errmsglen = linelen + 1;
}
+ // copy whole line to error message
STRLCPY(fields->errmsg, linebuf, linelen + 1);
+
+ return QF_OK;
}
/// Parse the match for error message ('%m') pattern in regmatch.
@@ -1495,7 +1498,7 @@ static int qf_parse_match(char *linebuf, size_t linelen, efm_T *fmt_ptr, regmatc
status = qf_parse_fmt_f(regmatch, midx, fields, idx);
} else if (i == FMT_PATTERN_M) {
if (fmt_ptr->flags == '+' && !qf_multiscan) { // %+
- qf_parse_fmt_plus(linebuf, linelen, fields);
+ status = copy_nonerror_line(linebuf, linelen, fields);
} else if (midx > 0) { // %m
status = qf_parse_fmt_m(regmatch, midx, fields);
}
@@ -1603,15 +1606,8 @@ static int qf_parse_line_nomatch(char *linebuf, size_t linelen, qffields_T *fiel
fields->namebuf[0] = NUL; // no match found, remove file name
fields->lnum = 0; // don't jump to this line
fields->valid = false;
- if (linelen >= fields->errmsglen) {
- // linelen + null terminator
- fields->errmsg = xrealloc(fields->errmsg, linelen + 1);
- fields->errmsglen = linelen + 1;
- }
- // copy whole line to error message
- STRLCPY(fields->errmsg, linebuf, linelen + 1);
- return QF_OK;
+ return copy_nonerror_line(linebuf, linelen, fields);
}
/// Parse multi-line error format prefixes (%C and %Z)