diff --git a/apps/statistics/histogram_parameter_controller.cpp b/apps/statistics/histogram_parameter_controller.cpp index 85a1ac89f..885556e49 100644 --- a/apps/statistics/histogram_parameter_controller.cpp +++ b/apps/statistics/histogram_parameter_controller.cpp @@ -50,12 +50,18 @@ float HistogramParameterController::parameterAtIndex(int index) { bool HistogramParameterController::setParameterAtIndex(int parameterIndex, float f) { assert(parameterIndex >= 0 && parameterIndex < k_numberOfCells); if (parameterIndex == 0) { - if (f <= 0.0f) { + float newNumberOfBars = ceilf((m_store->maxValue() - m_store->firstDrawnBarAbscissa())/f); + if (f <= 0.0f || newNumberOfBars > Store::k_maxNumberOfBars) { app()->displayWarning(I18n::Message::ForbiddenValue); return false; } m_store->setBarWidth(f); } else { + float newNumberOfBars = ceilf((m_store->maxValue() - f)/m_store->barWidth()); + if (newNumberOfBars > Store::k_maxNumberOfBars) { + app()->displayWarning(I18n::Message::ForbiddenValue); + return false; + } m_store->setFirstDrawnBarAbscissa(f); } return true; diff --git a/apps/statistics/store.h b/apps/statistics/store.h index 5f5d017cc..fa555dff9 100644 --- a/apps/statistics/store.h +++ b/apps/statistics/store.h @@ -37,6 +37,7 @@ public: float median(); float sum(); float squaredValueSum(); + constexpr static int k_maxNumberOfBars = 10000.0f; constexpr static float k_displayTopMarginRatio = 0.1f; constexpr static float k_displayRightMarginRatio = 0.04f; constexpr static float k_displayBottomMarginRatio = 0.4f;