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
This commit is contained in:
Thomas Vander Stichele 2005-10-13 15:23:51 +00:00
parent d4ea9fbeba
commit eecd25e78f
4 changed files with 45 additions and 1 deletions

View file

@ -1,3 +1,12 @@
2005-10-13 Thomas Vander Stichele <thomas at apestaart dot org>
* 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 <thomas at apestaart dot org> 2005-10-13 Thomas Vander Stichele <thomas at apestaart dot org>
* gst/base/gstbasesink.c: (gst_base_sink_handle_object): * gst/base/gstbasesink.c: (gst_base_sink_handle_object):

View file

@ -264,3 +264,32 @@ g_stat (const gchar * filename, struct stat *buf)
#endif #endif
} }
#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;
}

View file

@ -5,6 +5,7 @@
* Copyright 2005 David Schleef <ds@schleef.org> * Copyright 2005 David Schleef <ds@schleef.org>
*/ */
#include <gst_private.h> /* for g_warning */
#include <glib.h> #include <glib.h>
#if GLIB_CHECK_VERSION (2, 6, 0) #if GLIB_CHECK_VERSION (2, 6, 0)
#include <glib/gstdio.h> #include <glib/gstdio.h>
@ -26,5 +27,9 @@ struct stat;
int g_stat (const gchar *filename, struct stat *buf); int g_stat (const gchar *filename, struct stat *buf);
#endif #endif
#include <glib-object.h>
GFlagsValue*
gst_flags_get_first_value (GFlagsClass *flags_class,
guint value);
G_END_DECLS G_END_DECLS

View file

@ -32,6 +32,7 @@
#include <ctype.h> #include <ctype.h>
#include "gst_private.h" #include "gst_private.h"
#include "glib-compat.h"
#include <gst/gst.h> #include <gst/gst.h>
#include <gobject/gvaluecollector.h> #include <gobject/gvaluecollector.h>
@ -1570,7 +1571,7 @@ gst_value_serialize_flags (const GValue * value)
result = g_strdup (""); result = g_strdup ("");
flags = g_value_get_flags (value); flags = g_value_get_flags (value);
while (flags) { while (flags) {
fl = g_flags_get_first_value (klass, flags); fl = gst_flags_get_first_value (klass, flags);
if (fl != NULL) { if (fl != NULL) {
tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL); tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL);
g_free (result); g_free (result);