summaryrefslogtreecommitdiffstats
path: root/src/quickfix.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-02-15 23:06:45 +0100
committerBram Moolenaar <Bram@vim.org>2020-02-15 23:06:45 +0100
commitf4140488c72cad4dbf5449dba099cfa7de7bbb22 (patch)
treeef69c7720d31e0871cd01c41d447a5440e9d8e9c /src/quickfix.c
parentebdf3c964a901fc00c9009689f7cfda478342c51 (diff)
patch 8.2.0260: several lines of code are duplicatedv8.2.0260
Problem: Several lines of code are duplicated. Solution: Move duplicated code to a function. (Yegappan Lakshmanan, closes #5330)
Diffstat (limited to 'src/quickfix.c')
-rw-r--r--src/quickfix.c24
1 files changed, 7 insertions, 17 deletions
diff --git a/src/quickfix.c b/src/quickfix.c
index 00457e256d..f1df111212 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -980,11 +980,11 @@ qf_parse_fmt_t(regmatch_T *rmp, int midx, qffields_T *fields)
}
/*
- * Parse the match for '%+' format pattern. The whole matching line is included
- * in the error string. Return the matched line in "fields->errmsg".
+ * Copy a non-error line into the error string. Return the matched line in
+ * "fields->errmsg".
*/
static int
-qf_parse_fmt_plus(char_u *linebuf, int linelen, qffields_T *fields)
+copy_nonerror_line(char_u *linebuf, int linelen, qffields_T *fields)
{
char_u *p;
@@ -996,7 +996,9 @@ qf_parse_fmt_plus(char_u *linebuf, int linelen, qffields_T *fields)
fields->errmsg = p;
fields->errmsglen = linelen + 1;
}
+ // copy whole line to error message
vim_strncpy(fields->errmsg, linebuf, linelen);
+
return QF_OK;
}
@@ -1180,7 +1182,7 @@ qf_parse_match(
else if (i == 5)
{
if (fmt_ptr->flags == '+' && !qf_multiscan) // %+
- status = 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);
}
@@ -1307,23 +1309,11 @@ qf_parse_file_pfx(
static int
qf_parse_line_nomatch(char_u *linebuf, int linelen, qffields_T *fields)
{
- char_u *p;
-
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
- if ((p = vim_realloc(fields->errmsg, linelen + 1)) == NULL)
- return QF_NOMEM;
- fields->errmsg = p;
- fields->errmsglen = linelen + 1;
- }
- // copy whole line to error message
- vim_strncpy(fields->errmsg, linebuf, linelen);
- return QF_OK;
+ return copy_nonerror_line(linebuf, linelen, fields);
}
/*