[goffice] Ensure the validity of the dims property for linear regression curves.
- From: Jean Bréfort <jbrefort src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] Ensure the validity of the dims property for linear regression curves.
- Date: Mon, 26 Jan 2015 17:14:15 +0000 (UTC)
commit 7b37b6a1c09447c1faffb8d6dcea1da074b3e92c
Author: Jean Brefort <jean brefort normalesup org>
Date: Mon Jan 26 18:13:41 2015 +0100
Ensure the validity of the dims property for linear regression curves.
ChangeLog | 7 +++++++
NEWS | 3 +++
plugins/reg_linear/gog-lin-reg.c | 9 ++++++++-
plugins/reg_linear/gog-lin-reg.h | 1 +
plugins/reg_linear/gog-polynom-reg.c | 1 +
5 files changed, 20 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5720a03..a6ed697 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2015-01-26 Jean Brefort <jean brefort normalesup org>
+
+ * plugins/reg_linear/gog-lin-reg.c: ensure that the dims number is correct
+ in all cases. [see #743507]
+ * plugins/reg_linear/gog-lin-reg.h: ditto.
+ * plugins/reg_linear/gog-polynom-reg.c: ditto.
+
2015-01-23 Morten Welinder <terra gnome org>
* configure.ac: Post-release bump.
diff --git a/NEWS b/NEWS
index 5277426..ac83e8d 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
goffice 0.10.20:
+Jean:
+ * Ensure the validity of the dims property for linear regression curves.
+
--------------------------------------------------------------------------
goffice 0.10.19:
diff --git a/plugins/reg_linear/gog-lin-reg.c b/plugins/reg_linear/gog-lin-reg.c
index 7feb6c3..ede8adf 100644
--- a/plugins/reg_linear/gog-lin-reg.c
+++ b/plugins/reg_linear/gog-lin-reg.c
@@ -200,7 +200,8 @@ gog_lin_reg_curve_set_property (GObject *obj, guint param_id,
case REG_LIN_REG_CURVE_PROP_AFFINE:
rc->affine = g_value_get_boolean (value);
break;
- case REG_LIN_REG_CURVE_PROP_DIMS:
+ case REG_LIN_REG_CURVE_PROP_DIMS: {
+ int max_dims = ((GogLinRegCurveClass *) G_OBJECT_GET_CLASS (rc))->max_dims;
if (rc->x_vals) {
int i;
for (i = 0; i < rc->dims; i++){
@@ -210,9 +211,14 @@ gog_lin_reg_curve_set_property (GObject *obj, guint param_id,
g_free (rc->x_vals);
rc->x_vals = NULL;
rc->dims = g_value_get_uint (value);
+ if (rc->dims > max_dims) {
+ g_warning ("Invalid value %u for the \"dims\" property\n", rc->dims);
+ rc->dims = max_dims;
+ }
g_free (rc->base.a);
rc->base.a = g_new (double, rc->dims + 1);
break;
+ }
default: G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, param_id, pspec);
return; /* NOTE : RETURN */
@@ -258,6 +264,7 @@ gog_lin_reg_curve_class_init (GogRegCurveClass *reg_curve_klass)
lin_klass->lin_reg_func = go_linear_regression;
lin_klass->build_values = gog_lin_reg_curve_build_values;
+ lin_klass->max_dims = 1;
g_object_class_install_property (gobject_klass, REG_LIN_REG_CURVE_PROP_AFFINE,
g_param_spec_boolean ("affine",
diff --git a/plugins/reg_linear/gog-lin-reg.h b/plugins/reg_linear/gog-lin-reg.h
index a626f04..fa8b8ba 100644
--- a/plugins/reg_linear/gog-lin-reg.h
+++ b/plugins/reg_linear/gog-lin-reg.h
@@ -44,6 +44,7 @@ typedef struct {
go_regression_stat_t *stat);
int (*build_values) (GogLinRegCurve *rc, double const *x_vals,
double const *y_vals, int n);
+ int max_dims;
} GogLinRegCurveClass;
#define GOG_TYPE_LIN_REG_CURVE (gog_lin_reg_curve_get_type ())
diff --git a/plugins/reg_linear/gog-polynom-reg.c b/plugins/reg_linear/gog-polynom-reg.c
index c43b881..90004f8 100644
--- a/plugins/reg_linear/gog-polynom-reg.c
+++ b/plugins/reg_linear/gog-polynom-reg.c
@@ -231,6 +231,7 @@ gog_polynom_reg_curve_class_init (GogRegCurveClass *reg_curve_klass)
gog_polynom_reg_curve_parent_klass = g_type_class_peek_parent (reg_curve_klass);
lin_reg_klass->build_values = gog_polynom_reg_curve_build_values;
+ lin_reg_klass->max_dims = 10;
reg_curve_klass->get_value_at = gog_polynom_reg_curve_get_value_at;
reg_curve_klass->get_equation = gog_polynom_reg_curve_get_equation;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]