value: Handle serializing NULL GValueArray

Concider them as an empty array and do not segfault...

https://bugzilla.gnome.org/show_bug.cgi?id=786670
This commit is contained in:
Thibault Saunier 2017-08-26 13:44:38 -03:00
parent 39e21bb6dd
commit 996bedb81d
2 changed files with 21 additions and 1 deletions

View 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);

View 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;
}