From 3b72bfcd4fc4754793c168fceb542ca8caead792 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Thu, 13 Aug 2015 17:38:07 +0100 Subject: [PATCH] Fix SEGV LTM Edit .. when using Moving Average trend. --- src/LTMPlot.cpp | 100 +++++++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 48 deletions(-) diff --git a/src/LTMPlot.cpp b/src/LTMPlot.cpp index 13ee3411f..633b9b4c4 100644 --- a/src/LTMPlot.cpp +++ b/src/LTMPlot.cpp @@ -755,36 +755,38 @@ LTMPlot::setData(LTMSettings *set) // we need to fill in the gaps sadly int lcount = xdata[count]; - // calculated values - QVector xtrend(lcount); - QVector btrend(lcount); - QVector ytrend(lcount); + if (lcount) { + // calculated values + QVector xtrend(lcount); + QVector btrend(lcount); + QVector ytrend(lcount); - // initialise to same - ytrend.fill(0); - btrend.fill(0); + // initialise to same + ytrend.fill(0); + btrend.fill(0); - ytrend[0] = ydata[0]; - xtrend[0] = 0; + ytrend[0] = ydata[0]; + xtrend[0] = 0; - for (int n=1,i=1; i<= lcount; i++) { + for (int n=1,i=1; i<= lcount && isetSamples(xtrend.data(),ytrend.data(), xtrend.count()); + + trend->attach(this); + trend->setItemAttribute(QwtPlotItem::Legend, false); + curves.insert(trendSymbol, trend); } - - // point 2 is at far right of chart, not the last point - // since we may be forecasting... - trend->setSamples(xtrend.data(),ytrend.data(), xtrend.count()); - - trend->attach(this); - trend->setItemAttribute(QwtPlotItem::Legend, false); - curves.insert(trendSymbol, trend); } } @@ -1860,36 +1862,38 @@ LTMPlot::setCompareData(LTMSettings *set) // we need to fill in the gaps sadly int lcount = xdata[count]; - // calculated values - QVector xtrend(lcount); - QVector btrend(lcount); - QVector ytrend(lcount); + if (lcount) { + // calculated values + QVector xtrend(lcount); + QVector btrend(lcount); + QVector ytrend(lcount); - // initialise to same - ytrend.fill(0); - btrend.fill(0); + // initialise to same + ytrend.fill(0); + btrend.fill(0); - ytrend[0] = ydata[0]; - xtrend[0] = 0; + ytrend[0] = ydata[0]; + xtrend[0] = 0; - for (int n=1,i=1; i<= lcount; i++) { + for (int n=1,i=1; i<= lcount && isetSamples(xtrend.data(),ytrend.data(), xtrend.count()); + + trend->attach(this); + trend->setItemAttribute(QwtPlotItem::Legend, false); + curves.insert(trendSymbol, trend); } - - // point 2 is at far right of chart, not the last point - // since we may be forecasting... - trend->setSamples(xtrend.data(),ytrend.data(), xtrend.count()); - - trend->attach(this); - trend->setItemAttribute(QwtPlotItem::Legend, false); - curves.insert(trendSymbol, trend); } }