miniobject: Fix dup_mini_object function to handle NULL gvalues
authorThiago Santos <thiago.sousa.santos@collabora.co.uk>
Mon, 2 May 2011 14:30:06 +0000 (11:30 -0300)
committerThiago Santos <thiago.sousa.santos@collabora.co.uk>
Tue, 3 May 2011 11:15:51 +0000 (08:15 -0300)
g_value_dup_object handles gvalues that contain NULL pointers,
gst_value_dup_mini_object should do the same.

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

gst/gstminiobject.c
tests/check/gst/gstminiobject.c

index 49be565..4b46d29 100644 (file)
@@ -427,8 +427,8 @@ gst_value_mini_object_copy (const GValue * src_value, GValue * dest_value)
 {
   if (src_value->data[0].v_pointer) {
     dest_value->data[0].v_pointer =
-        gst_mini_object_ref (GST_MINI_OBJECT_CAST (src_value->data[0].
-            v_pointer));
+        gst_mini_object_ref (GST_MINI_OBJECT_CAST (src_value->
+            data[0].v_pointer));
   } else {
     dest_value->data[0].v_pointer = NULL;
   }
@@ -544,7 +544,8 @@ gst_value_get_mini_object (const GValue * value)
  * @value:   a valid #GValue of %GST_TYPE_MINI_OBJECT derived type
  *
  * Get the contents of a %GST_TYPE_MINI_OBJECT derived #GValue,
- * increasing its reference count.
+ * increasing its reference count. If the contents of the #GValue
+ * are %NULL, %NULL will be returned.
  *
  * Returns: (transfer full): mini object contents of @value
  *
@@ -555,7 +556,8 @@ gst_value_dup_mini_object (const GValue * value)
 {
   g_return_val_if_fail (GST_VALUE_HOLDS_MINI_OBJECT (value), NULL);
 
-  return gst_mini_object_ref (value->data[0].v_pointer);
+  return value->data[0].v_pointer ? gst_mini_object_ref (value->data[0].
+      v_pointer) : NULL;
 }
 
 
index 1477328..5c296db 100644 (file)
@@ -447,6 +447,23 @@ GST_START_TEST (test_value_collection)
 GST_END_TEST;
 
 
+GST_START_TEST (test_dup_null_mini_object)
+{
+  GValue value = { 0, };
+  GstBuffer *buf;
+
+  g_value_init (&value, GST_TYPE_BUFFER);
+
+  gst_value_set_mini_object (&value, NULL);
+
+  buf = gst_value_dup_mini_object (&value);
+  g_assert (buf == NULL);
+
+  g_value_unset (&value);
+}
+
+GST_END_TEST;
+
 static Suite *
 gst_mini_object_suite (void)
 {
@@ -464,6 +481,7 @@ gst_mini_object_suite (void)
   tcase_add_test (tc_chain, test_unref_threaded);
   tcase_add_test (tc_chain, test_recycle_threaded);
   tcase_add_test (tc_chain, test_value_collection);
+  tcase_add_test (tc_chain, test_dup_null_mini_object);
   return s;
 }