[goffice] Don't use a data vector with no valid value. [#741910]



commit 97712c9ea928ccc8fb80c8ea3f171c28c778b630
Author: Jean Brefort <jean brefort normalesup org>
Date:   Wed Jan 7 15:49:29 2015 +0100

    Don't use a data vector with no valid value. [#741910]

 ChangeLog                   |    9 +++++++++
 NEWS                        |    1 +
 goffice/data/go-data-impl.h |    3 ++-
 goffice/data/go-data.c      |   28 ++++++++++++++++++++++++++--
 goffice/data/go-data.h      |    1 +
 goffice/graph/gog-series.c  |    2 +-
 plugins/plot_xy/gog-xy.c    |    2 +-
 7 files changed, 41 insertions(+), 5 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 3297154..474f1d8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2015-01-07  Jean Brefort  <jean brefort normalesup org>
 
+       * goffice/data/go-data-impl.h: add GO_DATA_HAS_VALUE to GODataFlags.
+       * goffice/data/go-data.c: new go_data_has_value().
+       * goffice/data/go-data.h: ditto.
+       * goffice/graph/gog-series.c: don't use a data vector with no valid value.
+       [#741910]
+       * plugins/plot_xy/gog-xy.c: protect against NULL y vector.
+
+2015-01-07  Jean Brefort  <jean brefort normalesup org>
+
        * goffice/canvas/goc-canvas.c (goc_canvas_draw): implement native scrolling.
        [#741394]
 
diff --git a/NEWS b/NEWS
index 12e843a..377f092 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@ Jean:
        * Allow rotation of axis line labels. [#740198]
        * Move the title with its axis parent. [#684777]
        * Implement canvas native scrolling. [#741394]
+       * Don't use a data vector with no valid value. [#741910]
 
 Morten:
        * Dead kitten salvage.
diff --git a/goffice/data/go-data-impl.h b/goffice/data/go-data-impl.h
index b8c0e09..0906555 100644
--- a/goffice/data/go-data-impl.h
+++ b/goffice/data/go-data-impl.h
@@ -31,7 +31,8 @@ G_BEGIN_DECLS
 typedef enum {
        GO_DATA_CACHE_IS_VALID =        1 << 0,
        GO_DATA_IS_EDITABLE =           1 << 1,
-       GO_DATA_SIZE_CACHED =           1 << 2
+       GO_DATA_SIZE_CACHED =           1 << 2,
+       GO_DATA_HAS_VALUE = 1 << 3
 } GODataFlags;
 
 struct _GOData {
diff --git a/goffice/data/go-data.c b/goffice/data/go-data.c
index 2d46135..fa6d778 100644
--- a/goffice/data/go-data.c
+++ b/goffice/data/go-data.c
@@ -347,6 +347,15 @@ go_data_is_varying_uniformly (GOData *data)
        return go_data_check_variation (data, GO_DATA_VARIATION_CHECK_UNIFORMLY);
 }
 
+gboolean
+go_data_has_value (GOData const *data)
+{
+       g_return_val_if_fail (GO_IS_DATA (data), FALSE);
+       if (!(data->flags & GO_DATA_CACHE_IS_VALID))
+               go_data_get_values (GO_DATA (data));
+       return data->flags & GO_DATA_HAS_VALUE;
+}
+
 unsigned int
 go_data_get_n_dimensions (GOData *data)
 {
@@ -724,7 +733,7 @@ go_data_scalar_get_markup (GODataScalar *scalar)
 static void
 _data_vector_emit_changed (GOData *data)
 {
-       data->flags &= ~(GO_DATA_CACHE_IS_VALID | GO_DATA_VECTOR_LEN_CACHED);
+       data->flags &= ~(GO_DATA_CACHE_IS_VALID | GO_DATA_VECTOR_LEN_CACHED | GO_DATA_HAS_VALUE);
 }
 
 static unsigned int
@@ -816,6 +825,14 @@ go_data_vector_get_values (GODataVector *vec)
 
                (*klass->load_values) (vec);
 
+               {
+                       double min, max;
+                       go_data_get_bounds (&vec->base, &min, &max);
+                       if (go_finite (min) && go_finite (max) && min <= max)
+                               vec->base.flags |= GO_DATA_HAS_VALUE;
+
+               }
+
                g_return_val_if_fail (vec->base.flags & GO_DATA_CACHE_IS_VALID, NULL);
        }
 
@@ -921,7 +938,7 @@ go_data_vector_vary_uniformly (GODataVector *vec)
 static void
 _data_matrix_emit_changed (GOData *data)
 {
-       data->flags &= ~(GO_DATA_CACHE_IS_VALID | GO_DATA_MATRIX_SIZE_CACHED);
+       data->flags &= ~(GO_DATA_CACHE_IS_VALID | GO_DATA_MATRIX_SIZE_CACHED | GO_DATA_HAS_VALUE);
 }
 
 static unsigned int
@@ -1060,6 +1077,13 @@ go_data_matrix_get_values (GODataMatrix *mat)
 
                (*klass->load_values) (mat);
 
+               {
+                       double min, max;
+                       go_data_get_bounds (&mat->base, &min, &max);
+                       if (go_finite (min) && go_finite (max) && min <= max)
+                               mat->base.flags |= GO_DATA_HAS_VALUE;
+               }
+
                g_return_val_if_fail (mat->base.flags & GO_DATA_CACHE_IS_VALID, NULL);
        }
 
diff --git a/goffice/data/go-data.h b/goffice/data/go-data.h
index f163527..161c890 100644
--- a/goffice/data/go-data.h
+++ b/goffice/data/go-data.h
@@ -48,6 +48,7 @@ void          go_data_get_bounds              (GOData *data, double *minimum, double 
*maximum);
 gboolean       go_data_is_increasing           (GOData *data);
 gboolean       go_data_is_decreasing           (GOData *data);
 gboolean       go_data_is_varying_uniformly    (GOData *data);
+gboolean       go_data_has_value           (GOData const *data);
 
 unsigned int   go_data_get_n_dimensions        (GOData *data);
 unsigned int   go_data_get_n_values            (GOData *data);
diff --git a/goffice/graph/gog-series.c b/goffice/graph/gog-series.c
index 7569d2f..4ba0f8e 100644
--- a/goffice/graph/gog-series.c
+++ b/goffice/graph/gog-series.c
@@ -1256,7 +1256,7 @@ gog_series_get_data (GogSeries const *series, int *indices, double **data, int n
                index = indices != NULL ? indices[i] : i;
                if (index >= first && index <= last &&
                    (vector = series->values[index].data) != NULL) {
-                       data[i] = go_data_get_values (vector);
+                       data[i] = (go_data_has_value (vector))? go_data_get_values (vector): NULL;
                        vector_n_points = go_data_get_vector_size (vector);
                        if (!is_set) {
                                is_set = TRUE;
diff --git a/plugins/plot_xy/gog-xy.c b/plugins/plot_xy/gog-xy.c
index f72acdb..6d01de1 100644
--- a/plugins/plot_xy/gog-xy.c
+++ b/plugins/plot_xy/gog-xy.c
@@ -1118,7 +1118,7 @@ gog_xy_view_render (GogView *view, GogViewAllocation const *bbox)
                        n = gog_series_get_xyz_data (GOG_SERIES (series), &x_vals, &y_vals, &z_vals);
                else
                        n = gog_series_get_xy_data (GOG_SERIES (series), &x_vals, &y_vals);
-               if (n < 1)
+               if (n < 1 || y_vals == NULL)
                        continue;
 
                style = go_styled_object_get_style (GO_STYLED_OBJECT (series));


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