From eecd25e78fa4723bc97c3151b21d04ea603c904e Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Thu, 13 Oct 2005 15:23:51 +0000 Subject: [PATCH] gst/: GLib 2.6 g_flags_get_first_value has a bug that triggers an infinite loop Original commit message from CVS: * gst/glib-compat.c: (gst_flags_get_first_value): * gst/glib-compat.h: * gst/gstvalue.c: (gst_value_deserialize_int_helper), (gst_value_compare_double), (gst_value_serialize_flags): GLib 2.6 g_flags_get_first_value has a bug that triggers an infinite loop --- ChangeLog | 9 +++++++++ gst/glib-compat.c | 29 +++++++++++++++++++++++++++++ gst/glib-compat.h | 5 +++++ gst/gstvalue.c | 3 ++- 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 251d4ce..fc02086 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2005-10-13 Thomas Vander Stichele + * gst/glib-compat.c: (gst_flags_get_first_value): + * gst/glib-compat.h: + * gst/gstvalue.c: (gst_value_deserialize_int_helper), + (gst_value_compare_double), (gst_value_serialize_flags): + GLib 2.6 g_flags_get_first_value has a bug that triggers an + infinite loop + +2005-10-13 Thomas Vander Stichele + * gst/base/gstbasesink.c: (gst_base_sink_handle_object): * gst/base/gstbasesrc.c: (gst_base_src_get_range): fix up debugging diff --git a/gst/glib-compat.c b/gst/glib-compat.c index 7995961..85233ee 100644 --- a/gst/glib-compat.c +++ b/gst/glib-compat.c @@ -264,3 +264,32 @@ g_stat (const gchar * filename, struct stat *buf) #endif } #endif + +/* This version is copied from GLib 2.8. + * In GLib 2.6, it didn't check for a flag value being NULL, hence it + * hits an infinite loop in our flags serialize function + */ +GFlagsValue * +gst_flags_get_first_value (GFlagsClass * flags_class, guint value) +{ + g_return_val_if_fail (G_IS_FLAGS_CLASS (flags_class), NULL); + + if (flags_class->n_values) { + GFlagsValue *flags_value; + + if (value == 0) { + for (flags_value = flags_class->values; flags_value->value_name; + flags_value++) + if (flags_value->value == 0) + return flags_value; + } else { + for (flags_value = flags_class->values; flags_value->value_name; + flags_value++) + if (flags_value->value != 0 + && (flags_value->value & value) == flags_value->value) + return flags_value; + } + } + + return NULL; +} diff --git a/gst/glib-compat.h b/gst/glib-compat.h index 3b8e253..568d3d8 100644 --- a/gst/glib-compat.h +++ b/gst/glib-compat.h @@ -5,6 +5,7 @@ * Copyright 2005 David Schleef */ +#include /* for g_warning */ #include #if GLIB_CHECK_VERSION (2, 6, 0) #include @@ -26,5 +27,9 @@ struct stat; int g_stat (const gchar *filename, struct stat *buf); #endif +#include +GFlagsValue* +gst_flags_get_first_value (GFlagsClass *flags_class, + guint value); G_END_DECLS diff --git a/gst/gstvalue.c b/gst/gstvalue.c index af2c4a8..45c7599 100644 --- a/gst/gstvalue.c +++ b/gst/gstvalue.c @@ -32,6 +32,7 @@ #include #include "gst_private.h" +#include "glib-compat.h" #include #include @@ -1570,7 +1571,7 @@ gst_value_serialize_flags (const GValue * value) result = g_strdup (""); flags = g_value_get_flags (value); while (flags) { - fl = g_flags_get_first_value (klass, flags); + fl = gst_flags_get_first_value (klass, flags); if (fl != NULL) { tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL); g_free (result); -- 2.7.4