Skip to content
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

Reset current index in case it overflows out of range #245

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"header" should be "head"

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
Loading