From 503de0ae62847959af5ea9d1f8621adc1f8126e7 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Fri, 14 Jun 2019 22:18:57 +0200 Subject: [PATCH] Avoid -fsanitize=float-divide-by-zero ...when loading xls/tdf117254-4.xls as obtained by bin/get-bugzilla-attachments-by-mimetype (i.e., the attachment at ): > chart2/source/tools/PolynomialRegressionCurveCalculator.cxx:189:32: runtime error: division by zero > #0 in chart::PolynomialRegressionCurveCalculator::recalculateRegression(com::sun::star::uno::Sequence const&, com::sun::star::uno::Sequence const&) at chart2/source/tools/PolynomialRegressionCurveCalculator.cxx:189:32 > #1 in chart::VSeriesPlotter::createRegressionCurvesShapes(chart::VDataSeries const&, com::sun::star::uno::Reference const&, com::sun::star::uno::Reference const&, bool) at chart2/source/view/charttypes/VSeriesPlotter.cxx:1343:22 > #2 in chart::AreaChart::impl_createSeriesShapes() at chart2/source/view/charttypes/AreaChart.cxx:539:17 > #3 in chart::AreaChart::createShapes() at chart2/source/view/charttypes/AreaChart.cxx:965:5 > #4 in chart::ChartView::impl_createDiagramAndContent(chart::CreateShapeParam2D const&, com::sun::star::awt::Size const&) at chart2/source/view/main/ChartView.cxx:1608:25 > #5 in chart::ChartView::createShapes2D(com::sun::star::awt::Size const&) at chart2/source/view/main/ChartView.cxx:3037:41 > #6 in chart::ChartView::createShapes() at chart2/source/view/main/ChartView.cxx:2506:5 [...] Leaving aRSquared initialized to 0.0 when the divisor is zero is in line with the code prior to 00cb825ab3f16a94f1e8311ba0c24f72588e788e "fdo#75538 R^2 calculation for trendline similar to LINEST function" and with the recent nearby change f44d14e5f3909a4271034ba02da92ed2dee7b89c "Avoid -fsanitize=float-divide-by-zero". Change-Id: If2c17ad178788982729f647b4c695d3788fad500 Reviewed-on: https://gerrit.libreoffice.org/74068 Tested-by: Jenkins Reviewed-by: Laurent BP Reviewed-by: Stephan Bergmann --- chart2/source/tools/PolynomialRegressionCurveCalculator.cxx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx b/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx index 530d0d4a16a5..b087fc52cede 100644 --- a/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx +++ b/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx @@ -186,7 +186,10 @@ void SAL_CALL PolynomialRegressionCurveCalculator::recalculateRegression( double aRSquared = 0.0; if(mForceIntercept) { - aRSquared = aSumYpred2 / (aSumError + aSumYpred2); + if (auto const div = aSumError + aSumYpred2) + { + aRSquared = aSumYpred2 / div; + } } else if (aSumTotal != 0.0) {