summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Saunier <thibault.saunier@osg.samsung.com>2017-08-26 13:44:38 -0300
committerThibault Saunier <thibault.saunier@osg.samsung.com>2017-08-26 13:51:57 -0300
commit6a0b0b653e6d99a35fd7463a35fd2e928f4b3abd (patch)
treef37e6387285c64e621f20862992230122c903272
parent311df0166ff57e4bd989b5e526254d95eabcfb05 (diff)
value: Handle serializing NULL GValueArray
Consider them as an empty array and do not segfault... https://bugzilla.gnome.org/show_bug.cgi?id=786670
-rw-r--r--gst/gstvalue.c5
-rw-r--r--tests/check/gst/gstvalue.c17
2 files changed, 21 insertions, 1 deletions
diff --git a/gst/gstvalue.c b/gst/gstvalue.c
index 5bf719798..174de799e 100644
--- a/gst/gstvalue.c
+++ b/gst/gstvalue.c
@@ -276,7 +276,10 @@ _gst_value_serialize_g_value_array (const GValue * value, const gchar * begin,
GString *s;
GValue *v;
gchar *s_val;
- guint alen = array->n_values;
+ guint alen = 0;
+
+ if (array)
+ alen = array->n_values;
/* estimate minimum string length to minimise re-allocs in GString */
s = g_string_sized_new (2 + (6 * alen) + 2);
diff --git a/tests/check/gst/gstvalue.c b/tests/check/gst/gstvalue.c
index 639f175ee..483438311 100644
--- a/tests/check/gst/gstvalue.c
+++ b/tests/check/gst/gstvalue.c
@@ -3408,6 +3408,22 @@ GST_START_TEST (test_transform_list)
GST_END_TEST;
+GST_START_TEST (test_serialize_null_aray)
+{
+ gchar *serialized;
+ GValue v = G_VALUE_INIT;
+
+ g_value_init (&v, G_TYPE_VALUE_ARRAY);
+
+ g_value_set_boxed (&v, NULL);
+ serialized = gst_value_serialize (&v);
+ fail_unless_equals_string (serialized, "< >");
+ g_value_unset (&v);
+ g_free (serialized);
+}
+
+GST_END_TEST;
+
static Suite *
gst_value_suite (void)
{
@@ -3459,6 +3475,7 @@ gst_value_suite (void)
tcase_add_test (tc_chain, test_structure_ops);
tcase_add_test (tc_chain, test_transform_array);
tcase_add_test (tc_chain, test_transform_list);
+ tcase_add_test (tc_chain, test_serialize_null_aray);
return s;
}