[goffice] Don't crash when there are no x values for a moving average smoothing. [#708562]



commit c7afc7b97f120fdcdda7f125a814cea48b9195a7
Author: Jean Brefort <jean brefort normalesup org>
Date:   Mon Sep 23 09:06:19 2013 +0200

    Don't crash when there are no x values for a moving average smoothing. [#708562]

 ChangeLog                          |    8 +++++++-
 NEWS                               |    2 ++
 plugins/smoothing/gog-exp-smooth.c |    4 ++--
 plugins/smoothing/gog-moving-avg.c |    8 ++++----
 4 files changed, 15 insertions(+), 7 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ab10a5d..c85f477 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,13 @@
+2013-09-23  Jean Brefort  <jean brefort normalesup org>
+
+       * plugins/smoothing/gog-exp-smooth.c (gog_exp_smooth_update): protect
+       against missing x values. [#708562]
+       * plugins/smoothing/gog-moving-avg.c (gog_moving_avg_update): ditto.
+
 2013-09-21  Jean Brefort  <jean brefort normalesup org>
 
        * goffice/graph/gog-chart.c (gog_chart_axis_set_assign): do not remove
-extra axes after adding a plot. [#708292]
+       extra axes after adding a plot. [#708292]
 
 2013-09-20  Jean Brefort  <jean brefort normalesup org>
 
diff --git a/NEWS b/NEWS
index 9310f57..04db75a 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,8 @@ goffice 0.10.8:
 
 Jean:
        * Do not destroy axes after adding a plot using a restricted set. [#708292]
+       * Don't crash when there are no x values for a moving average smoothing.
+       [#708562]
 
 --------------------------------------------------------------------------
 goffice 0.10.7:
diff --git a/plugins/smoothing/gog-exp-smooth.c b/plugins/smoothing/gog-exp-smooth.c
index 522a344..06ce52f 100644
--- a/plugins/smoothing/gog-exp-smooth.c
+++ b/plugins/smoothing/gog-exp-smooth.c
@@ -109,9 +109,9 @@ gog_exp_smooth_update (GogObject *obj)
        y = g_new (double, nb);
        /* Remove invalid data */
        for (i = 0, n = 0; i < nb; i++) {
-               if (!go_finite (x_vals[i]) || !go_finite (y_vals[i]))
+               if ((x_vals && !go_finite (x_vals[i])) || !go_finite (y_vals[i]))
                        continue;
-               x[n] = x_vals[i];
+               x[n] = (x_vals)? x_vals[i]: i;
                y[n++] = y_vals[i];
        }
        go_range_min (x, n, &xmin);
diff --git a/plugins/smoothing/gog-moving-avg.c b/plugins/smoothing/gog-moving-avg.c
index ff4660d..8b7f578 100644
--- a/plugins/smoothing/gog-moving-avg.c
+++ b/plugins/smoothing/gog-moving-avg.c
@@ -140,7 +140,7 @@ gog_moving_avg_update (GogObject *obj)
        ma->base.y = g_new (double, ma->base.nb);
        invalid = ma->span;
        for (i = 0, j = 1 - ma->span; i < nb; i++, j++) {
-               if (!go_finite (x_vals[i]) || !go_finite (y_vals[i])) {
+               if ((x_vals && !go_finite (x_vals[i])) || !go_finite (y_vals[i])) {
                        invalid = ma->span;
                        xtot = ytot = 0;
                        if (j >= 0)
@@ -148,16 +148,16 @@ gog_moving_avg_update (GogObject *obj)
                        continue;
                }
                if (invalid == 0) {
-                       xtot -= x_vals[i - ma->span];
+                       xtot -= (x_vals)? x_vals[i - ma->span]: i - ma->span;
                        ytot -= y_vals[i - ma->span];
                } else
                        invalid --;
-               xtot += x_vals[i];
+               xtot += (x_vals)? x_vals[i]: i;
                ytot += y_vals[i];
                if (j >= 0) {
                        ma->base.x[j] = (ma->xavg)
                                ? ((invalid == 0) ? xtot / ma->span: go_nan)
-                               : x_vals[i];
+                               : ((x_vals)? x_vals[i]: i);
                        ma->base.y[j] = (invalid == 0)
                                ? ytot / ma->span
                                : go_nan;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]