diff --git a/subprojects/gstreamer/gst/gstvalue.c b/subprojects/gstreamer/gst/gstvalue.c index d6ee9254e2..543f8d31b7 100644 --- a/subprojects/gstreamer/gst/gstvalue.c +++ b/subprojects/gstreamer/gst/gstvalue.c @@ -4195,15 +4195,23 @@ gst_value_serialize_gflags (const GValue * value) result = g_strdup (""); while (flags) { fl = g_flags_get_first_value (klass, flags); - if (fl != NULL) { - tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL); - g_free (result); - result = tmp; - first = FALSE; - - /* clear flag */ - flags &= ~fl->value; + if (fl == NULL) { + if (flags) { + g_critical ("Could not serialize invalid flags 0x%x of type %s", + flags, G_VALUE_TYPE_NAME (value)); + g_free (result); + result = g_strdup ("0"); + } + break; } + + tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL); + g_free (result); + result = tmp; + first = FALSE; + + /* clear flag */ + flags &= ~fl->value; } g_type_class_unref (klass); diff --git a/subprojects/gstreamer/tests/check/gst/gstvalue.c b/subprojects/gstreamer/tests/check/gst/gstvalue.c index b86eef4e78..3a4ccfb239 100644 --- a/subprojects/gstreamer/tests/check/gst/gstvalue.c +++ b/subprojects/gstreamer/tests/check/gst/gstvalue.c @@ -447,6 +447,31 @@ GST_START_TEST (test_serialize_flags) GST_END_TEST; +GST_START_TEST (test_serialize_flags_invalid) +{ + GValue value = { 0 }; + gchar *string; + + g_value_init (&value, GST_TYPE_SEEK_FLAGS); + + /* Invalid value */ + g_value_set_flags (&value, 1 << 20); + ASSERT_CRITICAL (string = gst_value_serialize (&value)); + fail_if (string == NULL, "could not serialize invalid flags"); + fail_unless (strcmp (string, "0") == 0, + "resulting value is %s, not 0, for invalid flags", string); + g_free (string); + + /* Valid & invalid value */ + g_value_set_flags (&value, GST_SEEK_FLAG_FLUSH | 1 << 20); + ASSERT_CRITICAL (string = gst_value_serialize (&value)); + fail_if (string == NULL, "could not serialize invalid flags"); + fail_unless (strcmp (string, "0") == 0, + "resulting value is %s, not 0, for invalid flags", string); + g_free (string); +} + +GST_END_TEST; GST_START_TEST (test_deserialize_flags) { @@ -3937,6 +3962,7 @@ gst_value_suite (void) tcase_add_test (tc_chain, test_deserialize_bitmask); tcase_add_test (tc_chain, test_deserialize_array); tcase_add_test (tc_chain, test_serialize_flags); + tcase_add_test (tc_chain, test_serialize_flags_invalid); tcase_add_test (tc_chain, test_deserialize_flags); tcase_add_test (tc_chain, test_serialize_deserialize_format_enum); tcase_add_test (tc_chain, test_serialize_deserialize_value_array);