value: Handle serializing NULL GValueArray
authorThibault Saunier <thibault.saunier@osg.samsung.com>
Sat, 26 Aug 2017 16:44:38 +0000 (13:44 -0300)
committerThibault Saunier <thibault.saunier@osg.samsung.com>
Sat, 26 Aug 2017 16:46:58 +0000 (13:46 -0300)
Concider them as an empty array and do not segfault...

https://bugzilla.gnome.org/show_bug.cgi?id=786670

gst/gstvalue.c
tests/check/gst/gstvalue.c

index 5bf7197..174de79 100644 (file)
@@ -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);
index 639f175..4834383 100644 (file)
@@ -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;
 }