-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Refactor the qf_parse_line() function in quickfix.c #2881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/quickfix.c
Outdated
| if (linelen >= fields->errmsglen) | ||
| { | ||
| /* linelen + null terminator */ | ||
| if ((fields->errmsg = vim_realloc(fields->errmsg, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This way of calling realloc leaks memory if realloc(…) fails i.e. if it returns NULL.
See https://www.viva64.com/en/w/v701/ for more details.
src/quickfix.c
Outdated
| if (len >= fields->errmsglen) | ||
| { | ||
| /* len + null terminator */ | ||
| if ((fields->errmsg = vim_realloc(fields->errmsg, len + 1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same remark: leak if vim_realloc(…) returns NULL.
src/quickfix.c
Outdated
| if (linelen >= fields->errmsglen) | ||
| { | ||
| /* linelen + null terminator */ | ||
| if ((fields->errmsg = vim_realloc(fields->errmsg, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leak if vim_realloc(…) fails.
|
Hi,
On Mon, May 7, 2018 at 12:12 AM, Dominique Pellé ***@***.***> wrote:
@dpelle commented on this pull request.
________________________________
In src/quickfix.c:
> + if (regmatch->startp[i] == NULL)
+ return QF_FAIL;
+ fields->col = (int)atol((char *)regmatch->startp[i]);
+ }
+ if ((i = (int)fmt_ptr->addr[4]) > 0) /* %t */
+ {
+ if (regmatch->startp[i] == NULL)
+ return QF_FAIL;
+ fields->type = *regmatch->startp[i];
+ }
+ if (fmt_ptr->flags == '+' && !qf_multiscan) /* %+ */
+ {
+ if (linelen >= fields->errmsglen)
+ {
+ /* linelen + null terminator */
+ if ((fields->errmsg = vim_realloc(fields->errmsg,
This way of calling realloc leaks memory if realloc(…) fails i.e. if it
returns NULL.
See https://www.viva64.com/en/w/v701/ for more details.
Thanks for pointing this out. I have pushed out a new commit that
fixes this issue. I have also fixed other places in quickfix.c where
vim_realloc() is used.
Thanks,
Yegappan
…
________________________________
In src/quickfix.c:
> + if ((fields->errmsg = vim_realloc(fields->errmsg,
+ linelen + 1)) == NULL)
+ return QF_NOMEM;
+ fields->errmsglen = linelen + 1;
+ }
+ vim_strncpy(fields->errmsg, linebuf, linelen);
+ }
+ else if ((i = (int)fmt_ptr->addr[5]) > 0) /* %m */
+ {
+ if (regmatch->startp[i] == NULL || regmatch->endp[i] == NULL)
+ return QF_FAIL;
+ len = (int)(regmatch->endp[i] - regmatch->startp[i]);
+ if (len >= fields->errmsglen)
+ {
+ /* len + null terminator */
+ if ((fields->errmsg = vim_realloc(fields->errmsg, len + 1))
Same remark: leak if vim_realloc(…) returns NULL.
________________________________
In src/quickfix.c:
> +}
+
+/*
+ * Parse a non-error line (a line which doesn't match any of the error
+ * format in 'efm').
+ */
+ static int
+qf_parse_line_nomatch(char_u *linebuf, int linelen, qffields_T *fields)
+{
+ 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 ((fields->errmsg = vim_realloc(fields->errmsg,
Leak if vim_realloc(…) fails.
|
Codecov Report
@@ Coverage Diff @@
## master #2881 +/- ##
==========================================
+ Coverage 75.53% 75.55% +0.02%
==========================================
Files 92 92
Lines 134866 134900 +34
==========================================
+ Hits 101867 101930 +63
+ Misses 32999 32970 -29
Continue to review full report at Codecov.
|
Problem: qf_parse_line() is too long.
Solution: Split it in parts. Properly handle vim_realloc() failing.
(Yegappan Lakshmanan, closes vim#2881)
Problem: qf_parse_line() is too long.
Solution: Split it in parts. Properly handle vim_realloc() failing.
(Yegappan Lakshmanan, closes vim/vim#2881)
vim/vim@18cebf4
Problem: qf_parse_line() is too long.
Solution: Split it in parts. Properly handle vim_realloc() failing.
(Yegappan Lakshmanan, closes vim/vim#2881)
vim/vim@18cebf4
Problem: qf_parse_line() is too long.
Solution: Split it in parts. Properly handle vim_realloc() failing.
(Yegappan Lakshmanan, closes vim/vim#2881)
vim/vim@18cebf4
Problem: qf_parse_line() is too long.
Solution: Split it in parts. Properly handle vim_realloc() failing.
(Yegappan Lakshmanan, closes vim/vim#2881)
vim/vim@18cebf4
Problem: qf_parse_line() is too long.
Solution: Split it in parts. Properly handle vim_realloc() failing.
(Yegappan Lakshmanan, closes vim/vim#2881)
vim/vim@18cebf4
Problem: qf_parse_line() is too long.
Solution: Split it in parts. Properly handle vim_realloc() failing.
(Yegappan Lakshmanan, closes vim/vim#2881)
vim/vim@18cebf4
Problem: qf_parse_line() is too long.
Solution: Split it in parts. Properly handle vim_realloc() failing.
(Yegappan Lakshmanan, closes vim/vim#2881)
vim/vim@18cebf4
The qf_parse_line() function in quickfix.c is too long. Refactor the function.
Add additional comments to some of the functions. No new functionality
is introduced in this patch.