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:
luukvbaal 2023-12-11 17:16:35 +01:00 committed by GitHub
parent c95b9a32f8
commit 6d698c86d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -719,7 +719,7 @@ void decor_redraw_signs(win_T *wp, buf_T *buf, int row, SignTextAttrs sattrs[],
int *cul_id, int *num_id)
{
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;
}
@ -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.
}
int count = 0; // Number of signs on the current row
int currow = row1;
MTPair pair = { 0 };
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));
// 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)) {
if (!mt_invalid(pair.start) && pair.start.flags & MT_FLAG_DECOR_SIGNTEXT) {
overlap[0]++;
}
}
// Continue traversing the marktree until beyond "row2". Increment "count" for
// the start of a mark, increment the overlap array until the end of a paired mark.
// Continue traversing the marktree until beyond "row2".
while (itr->x) {
MTKey mark = marktree_itr_current(itr);
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.
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;
count = 0;
}
// Increment count and overlap array for the range of a paired sign mark.
// Increment overlap array for the start and range of a paired sign mark.
if (!mt_invalid(mark) && !mt_end(mark) && (mark.flags & MT_FLAG_DECOR_SIGNTEXT)) {
count++;
if (mt_paired(mark)) {
MTPos end = marktree_get_altpos(buf->b_marktree, mark, NULL);
for (int i = mark.pos.row + 1; i <= MIN(row2, end.row); i++) {
overlap[i - row1]++;
}
MTPos end = marktree_get_altpos(buf->b_marktree, mark, NULL);
for (int i = currow; i <= MIN(row2, end.row < 0 ? currow : end.row); i++) {
overlap[i - row1]++;
}
}
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);
}