[goffice] Various: sanity check types before creating objects based on names.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] Various: sanity check types before creating objects based on names.
- Date: Thu, 18 Jun 2015 16:38:54 +0000 (UTC)
commit 36df9babd3099ed12d5885b3f807e8a84998661a
Author: Morten Welinder <terra gnome org>
Date: Thu Jun 18 12:37:38 2015 -0400
Various: sanity check types before creating objects based on names.
In principle a type constructor can do all kinds of things. We want
to check that a type is derived from the right base before we create
objects of that type.
ChangeLog | 11 +++++++++++
goffice/app/go-doc.c | 2 +-
goffice/graph/gog-object-xml.c | 4 +++-
goffice/graph/gog-plot-engine.c | 3 +++
4 files changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 474d52c..cb4ddf0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2015-06-18 Morten Welinder <terra gnome org>
+
+ * goffice/app/go-doc.c (go_doc_image_fetch): Sanity check image
+ type.
+
+ * goffice/graph/gog-object-xml.c (gogo_start): Sanity check object
+ type.
+
+ * goffice/graph/gog-plot-engine.c (gog_plot_new_by_name)
+ (gog_trend_line_new_by_name): Sanity check type name.
+
2015-06-17 Jean Brefort <jean brefort normalesup org>
* goffice/graph/gog-object.c (gog_object_get_child_by_role): protect against
diff --git a/goffice/app/go-doc.c b/goffice/app/go-doc.c
index 043cd36..1587c3b 100644
--- a/goffice/app/go-doc.c
+++ b/goffice/app/go-doc.c
@@ -675,7 +675,7 @@ go_doc_image_fetch (GODoc *doc, char const *id, GType type)
g_return_val_if_fail (doc && doc->priv->imagebuf, NULL);
image = g_hash_table_lookup (doc->priv->imagebuf, id);
if (!image) {
- g_return_val_if_fail (type != 0, NULL);
+ g_return_val_if_fail (g_type_is_a (type, GO_TYPE_IMAGE), NULL);
image = g_object_new (type, NULL);
if (!GO_IS_IMAGE (image)) {
if (image)
diff --git a/goffice/graph/gog-object-xml.c b/goffice/graph/gog-object-xml.c
index 73f6015..308c281 100644
--- a/goffice/graph/gog-object-xml.c
+++ b/goffice/graph/gog-object-xml.c
@@ -452,8 +452,10 @@ gogo_start (GsfXMLIn *xin, xmlChar const **attrs)
res = (GogObject *)gog_plot_new_by_name (type);
if (NULL == res)
res = (GogObject *)gog_trend_line_new_by_name (type);
- } else
+ } else if (g_type_is_a (t, GOG_TYPE_OBJECT))
res = g_object_new (t, NULL);
+ else
+ res = NULL;
if (res == NULL) {
g_warning ("unknown type '%s'", type);
diff --git a/goffice/graph/gog-plot-engine.c b/goffice/graph/gog-plot-engine.c
index 1221acf..488124b 100644
--- a/goffice/graph/gog-plot-engine.c
+++ b/goffice/graph/gog-plot-engine.c
@@ -132,6 +132,7 @@ gog_plot_new_by_name (char const *id)
g_object_ref (plugin);
go_plugin_use_ref (plugin);
}
+ g_return_val_if_fail (g_type_is_a (type, GOG_TYPE_PLOT), NULL);
return g_object_new (type, NULL);
}
@@ -470,9 +471,11 @@ gog_trend_line_new_by_name (char const *id)
g_object_ref (plugin);
go_plugin_use_ref (plugin);
}
+ g_return_val_if_fail (g_type_is_a (type, GOG_TYPE_TREND_LINE), NULL);
return g_object_new (type, NULL);
}
+
/***************************************************************************/
/* Use a plugin service to define regression curves types */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]