mirror of
https://github.com/neovim/neovim
synced 2025-07-16 01:01:49 +00:00
fix(coverity): unhandled retval for marktree_itr_get_overlap() #26518
buf_signcols_validate_range() is only called in a buffer with signs, in which the marktree is thus non-empty. Also remove a redundant comment, condition and variable. *** CID 470331: Error handling issues (CHECKED_RETURN) /src/nvim/decoration.c: 824 in buf_signcols_validate_range() 818 819 // Allocate an array of integers holding the overlapping signs in the range. 820 assert(row2 >= row1); 821 int *overlap = xcalloc(sizeof(int), (size_t)(row2 + 1 - row1)); 822 823 // First find the number of overlapping signs at "row1". >>> CID 470331: Error handling issues (CHECKED_RETURN) >>> Calling "marktree_itr_get_overlap" without checking return value (as is done elsewhere 4 out of 5 times). 824 marktree_itr_get_overlap(buf->b_marktree, currow, 0, itr); 825 while (marktree_itr_step_overlap(buf->b_marktree, itr, &pair)) { 826 if (!mt_invalid(pair.start) && pair.start.flags & MT_FLAG_DECOR_SIGNTEXT) { 827 overlap[0]++; 828 } 829 }
This commit is contained in:
@ -719,7 +719,7 @@ void decor_redraw_signs(win_T *wp, buf_T *buf, int row, SignTextAttrs sattrs[],
|
|||||||
int *cul_id, int *num_id)
|
int *cul_id, int *num_id)
|
||||||
{
|
{
|
||||||
MarkTreeIter itr[1];
|
MarkTreeIter itr[1];
|
||||||
if (!buf->b_signs || !marktree_itr_get_overlap(buf->b_marktree, row, 0, itr)) {
|
if (!marktree_itr_get_overlap(buf->b_marktree, row, 0, itr)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -815,7 +815,6 @@ static void buf_signcols_validate_range(buf_T *buf, int row1, int row2, int add)
|
|||||||
return; // max signs were removed from the range, no need to count.
|
return; // max signs were removed from the range, no need to count.
|
||||||
}
|
}
|
||||||
|
|
||||||
int count = 0; // Number of signs on the current row
|
|
||||||
int currow = row1;
|
int currow = row1;
|
||||||
MTPair pair = { 0 };
|
MTPair pair = { 0 };
|
||||||
MarkTreeIter itr[1];
|
MarkTreeIter itr[1];
|
||||||
@ -825,15 +824,14 @@ static void buf_signcols_validate_range(buf_T *buf, int row1, int row2, int add)
|
|||||||
int *overlap = xcalloc(sizeof(int), (size_t)(row2 + 1 - row1));
|
int *overlap = xcalloc(sizeof(int), (size_t)(row2 + 1 - row1));
|
||||||
|
|
||||||
// First find the number of overlapping signs at "row1".
|
// First find the number of overlapping signs at "row1".
|
||||||
marktree_itr_get_overlap(buf->b_marktree, currow, 0, itr);
|
(void)marktree_itr_get_overlap(buf->b_marktree, currow, 0, itr);
|
||||||
while (marktree_itr_step_overlap(buf->b_marktree, itr, &pair)) {
|
while (marktree_itr_step_overlap(buf->b_marktree, itr, &pair)) {
|
||||||
if (!mt_invalid(pair.start) && pair.start.flags & MT_FLAG_DECOR_SIGNTEXT) {
|
if (!mt_invalid(pair.start) && pair.start.flags & MT_FLAG_DECOR_SIGNTEXT) {
|
||||||
overlap[0]++;
|
overlap[0]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Continue traversing the marktree until beyond "row2". Increment "count" for
|
// Continue traversing the marktree until beyond "row2".
|
||||||
// the start of a mark, increment the overlap array until the end of a paired mark.
|
|
||||||
while (itr->x) {
|
while (itr->x) {
|
||||||
MTKey mark = marktree_itr_current(itr);
|
MTKey mark = marktree_itr_current(itr);
|
||||||
if (mark.pos.row > row2) {
|
if (mark.pos.row > row2) {
|
||||||
@ -841,25 +839,20 @@ static void buf_signcols_validate_range(buf_T *buf, int row1, int row2, int add)
|
|||||||
}
|
}
|
||||||
// Finish the count at the previous row.
|
// Finish the count at the previous row.
|
||||||
if (mark.pos.row != currow) {
|
if (mark.pos.row != currow) {
|
||||||
buf_signcols_validate_row(buf, count + overlap[currow - row1], add);
|
buf_signcols_validate_row(buf, overlap[currow - row1], add);
|
||||||
currow = mark.pos.row;
|
currow = mark.pos.row;
|
||||||
count = 0;
|
|
||||||
}
|
}
|
||||||
|
// Increment overlap array for the start and range of a paired sign mark.
|
||||||
// Increment count and overlap array for the range of a paired sign mark.
|
|
||||||
if (!mt_invalid(mark) && !mt_end(mark) && (mark.flags & MT_FLAG_DECOR_SIGNTEXT)) {
|
if (!mt_invalid(mark) && !mt_end(mark) && (mark.flags & MT_FLAG_DECOR_SIGNTEXT)) {
|
||||||
count++;
|
MTPos end = marktree_get_altpos(buf->b_marktree, mark, NULL);
|
||||||
if (mt_paired(mark)) {
|
for (int i = currow; i <= MIN(row2, end.row < 0 ? currow : end.row); i++) {
|
||||||
MTPos end = marktree_get_altpos(buf->b_marktree, mark, NULL);
|
overlap[i - row1]++;
|
||||||
for (int i = mark.pos.row + 1; i <= MIN(row2, end.row); i++) {
|
|
||||||
overlap[i - row1]++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
marktree_itr_next(buf->b_marktree, itr);
|
marktree_itr_next(buf->b_marktree, itr);
|
||||||
}
|
}
|
||||||
buf_signcols_validate_row(buf, count + overlap[currow - row1], add);
|
buf_signcols_validate_row(buf, overlap[currow - row1], add);
|
||||||
xfree(overlap);
|
xfree(overlap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user