From fe4e2e3e9d1b4d59bf2f0dc3b4e1fe438aac9059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 8 Dec 2020 10:45:49 +0100 Subject: [PATCH] Misc. clang static analyzer fixes --- apps/regression/model/model.cpp | 1 + apps/shared/localization_controller.cpp | 1 + apps/title_bar_view.cpp | 1 + escher/src/table_cell.cpp | 1 + poincare/src/zoom.cpp | 2 +- 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/regression/model/model.cpp b/apps/regression/model/model.cpp index 13f711574..2d223ec7e 100644 --- a/apps/regression/model/model.cpp +++ b/apps/regression/model/model.cpp @@ -64,6 +64,7 @@ void Model::fitLevenbergMarquardt(Store * store, int series, double * modelCoeff while (smallChi2ChangeCounts < k_consecutiveSmallChi2ChangesLimit && iterationCount < k_maxIterations) { // Create the alpha prime matrix (it is symmetric) double coefficientsAPrime[Model::k_maxNumberOfCoefficients * Model::k_maxNumberOfCoefficients]; + assert(n > 0); // Ensure that coefficientsAPrime is initialized for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { double alphaPrime = alphaPrimeCoefficient(store, series, modelCoefficients, i, j, lambda); diff --git a/apps/shared/localization_controller.cpp b/apps/shared/localization_controller.cpp index 92ff1bd2c..a0a99d43e 100644 --- a/apps/shared/localization_controller.cpp +++ b/apps/shared/localization_controller.cpp @@ -15,6 +15,7 @@ LocalizationController::ContentView::ContentView(LocalizationController * contro { m_countryTitleMessage.setBackgroundColor(Palette::WallScreen); m_countryTitleMessage.setAlignment(0.5f, 0.5f); + assert(k_numberOfCountryWarningLines == 2); // textMessages is not overflowed I18n::Message textMessages[k_numberOfCountryWarningLines] = {I18n::Message::CountryWarning1, I18n::Message::CountryWarning2}; for (int i = 0; i < k_numberOfCountryWarningLines; i++) { m_countryWarningLines[i].setBackgroundColor(Palette::WallScreen); diff --git a/apps/title_bar_view.cpp b/apps/title_bar_view.cpp index ed6be0b4a..3295a0f5e 100644 --- a/apps/title_bar_view.cpp +++ b/apps/title_bar_view.cpp @@ -107,6 +107,7 @@ void TitleBarView::refreshPreferences() { I18n::Message::Deg : (angleUnit == Preferences::AngleUnit::Radian ? I18n::Message::Rad : I18n::Message::Gon); numberOfChar += strlcpy(buffer+numberOfChar, I18n::translate(angleMessage), bufferSize - numberOfChar); + assert(numberOfChar < bufferSize-1); } m_preferenceView.setText(buffer); // Layout the exam mode icon if needed diff --git a/escher/src/table_cell.cpp b/escher/src/table_cell.cpp index 1bf949448..1fc07ea79 100644 --- a/escher/src/table_cell.cpp +++ b/escher/src/table_cell.cpp @@ -101,6 +101,7 @@ void TableCell::layoutSubviews(bool force) { y = std::max(y, height - k_separatorThickness - withMargin(accessorySize.height(), k_verticalMargin) - withMargin(subAccessorySize.height(), 0)); if (subAccessory) { KDCoordinate subAccessoryHeight = std::min(subAccessorySize.height(), height - y - k_separatorThickness - k_verticalMargin); + assert(accessory); accessory->setFrame(KDRect(horizontalMargin, y, width - 2*horizontalMargin, subAccessoryHeight), force); y += subAccessoryHeight; } diff --git a/poincare/src/zoom.cpp b/poincare/src/zoom.cpp index ac9eb6390..ab278aaa5 100644 --- a/poincare/src/zoom.cpp +++ b/poincare/src/zoom.cpp @@ -294,7 +294,7 @@ void Zoom::RangeWithRatioForDisplay(ValueAtAbscissa evaluation, float yxRatio, f * dealing with linear functions. */ float yRange = yxRatio * xRange; int j = 1; - int bestIndex, bestBreadth = 0, bestDistanceToCenter; + int bestIndex = 0, bestBreadth = 0, bestDistanceToCenter; for (int i = 0; i < sampleSize; i++) { if (sampleSize - i < bestBreadth) { break;