From dba85cc56a062559544fbfa69aaa564e16a2fbd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Fri, 28 Oct 2016 11:58:59 +0200 Subject: [PATCH] [apps/calculation] Correct error in ring buffer methods Change-Id: I684afe462d23384a4807644586c03ea654ed7c8a --- apps/calculation/calculation_store.cpp | 13 +++++++------ apps/calculation/calculation_store.h | 2 ++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/apps/calculation/calculation_store.cpp b/apps/calculation/calculation_store.cpp index b93b0e203..254875dc0 100644 --- a/apps/calculation/calculation_store.cpp +++ b/apps/calculation/calculation_store.cpp @@ -20,16 +20,17 @@ Calculation * CalculationStore::push(Calculation * c) { Calculation * CalculationStore::calculationAtIndex(int i) { int j = 0; Calculation * currentCalc = m_start; - while (j<=i) { + Calculation * previousCalc = nullptr; + while (j <= i) { + if (!currentCalc++->isEmpty()) { + previousCalc = currentCalc - 1; + j++; + } if (currentCalc >= m_calculations + k_maxNumberOfCalculations) { currentCalc = m_calculations; } - if (!currentCalc->isEmpty()) { - j++; - } - currentCalc++; } - return currentCalc-1; + return previousCalc; } int CalculationStore::numberOfCalculations() { diff --git a/apps/calculation/calculation_store.h b/apps/calculation/calculation_store.h index 4d67ef4fc..fb8ee15e7 100644 --- a/apps/calculation/calculation_store.h +++ b/apps/calculation/calculation_store.h @@ -5,6 +5,8 @@ namespace Calculation { +// TODO: make tests for the ring buffer + class CalculationStore { public: CalculationStore();