From 8085503a2e48d906254ef48bc524368c58c29ec0 Mon Sep 17 00:00:00 2001 From: jdelapla Date: Tue, 13 Feb 2024 10:57:12 -0800 Subject: [PATCH] Reset current index in case it overflows out of range (#245) --- src/view/src/ContentView.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/view/src/ContentView.c b/src/view/src/ContentView.c index 9f035dc1a..9a3f2befb 100644 --- a/src/view/src/ContentView.c +++ b/src/view/src/ContentView.c @@ -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); @@ -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: