Skip to content

Commit

Permalink
Reset current index in case it overflows out of range (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdelapla committed Feb 13, 2024
1 parent 1287aaa commit 8085503
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/view/src/ContentView.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ STATUS contentViewGetNext(PContentView pContentView, PViewItem* ppItem)
// Quick check if any items exist - early return
CHK((pRollingView->head != pRollingView->tail) && (pRollingView->current != pRollingView->head), STATUS_CONTENT_VIEW_NO_MORE_ITEMS);

// current is greater than the header & head isn't currently in an overflow state.
if (pRollingView->current > pRollingView->head && pRollingView->head > pRollingView->tail) {
// current index has broken outside the rolling buffer
// reset the index, and return error
DLOGI("Current index overflow state discovered! Resetting");
pRollingView->current = pRollingView->tail;
CHK(FALSE, STATUS_CONTENT_VIEW_INVALID_INDEX);
}

// Get the current item
pCurrent = GET_VIEW_ITEM_FROM_INDEX(pRollingView, pRollingView->current);

Expand Down Expand Up @@ -322,16 +331,16 @@ STATUS contentViewRollbackCurrent(PContentView pContentView, UINT64 duration, BO
break;
}

// Terminate the loop if we reached the head
if (curIndex == pRollingView->head) {
break;
}

// Iterate forward
curIndex++;

// Set the current
pRollingView->current = curIndex;

// Terminate the loop if we reached the head
if (curIndex == pRollingView->head) {
break;
}
}

CleanUp:
Expand Down

0 comments on commit 8085503

Please sign in to comment.