[glib] gvaluetransform: Fix an infinite loop with GFlagsValue sets with the 0 value
- From: Rui Matos <rtcm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gvaluetransform: Fix an infinite loop with GFlagsValue sets with the 0 value
- Date: Wed, 22 Feb 2012 13:04:56 +0000 (UTC)
commit 9ff09f34cf0bc5fbc951490923880d82d94862d1
Author: Rui Matos <tiagomatos gmail com>
Date: Tue Feb 21 16:42:43 2012 +0100
gvaluetransform: Fix an infinite loop with GFlagsValue sets with the 0 value
Transforming a GValue holding flags from a GFlagsValue set that includes the 0
value (no flag bits set) into a string would loop until exhausting all the
available memory.
https://bugzilla.gnome.org/show_bug.cgi?id=670557
gobject/gvaluetransform.c | 2 +-
gobject/tests/enums.c | 16 ++++++++++++++--
2 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/gobject/gvaluetransform.c b/gobject/gvaluetransform.c
index 2352be5..a785817 100644
--- a/gobject/gvaluetransform.c
+++ b/gobject/gvaluetransform.c
@@ -216,7 +216,7 @@ value_transform_flags_string (const GValue *src_value,
g_string_append (gstring, flags_value->value_name);
flags_value = g_flags_get_first_value (class, v_flags);
}
- while (flags_value);
+ while (flags_value && v_flags);
if (v_flags)
dest_value->data[0].v_pointer = g_strdup_printf ("%s | %u",
diff --git a/gobject/tests/enums.c b/gobject/tests/enums.c
index e744bed..72df8a8 100644
--- a/gobject/tests/enums.c
+++ b/gobject/tests/enums.c
@@ -52,12 +52,22 @@ test_enum_basic (void)
static const GFlagsValue my_flag_values[] =
{
+ { 0, "no flags", "none" },
{ 1, "the first flag", "one" },
{ 2, "the second flag", "two" },
{ 8, "the third flag", "three" },
{ 0, NULL, NULL }
};
+static void
+test_flags_transform_to_string (const GValue *value)
+{
+ GValue tmp = G_VALUE_INIT;
+
+ g_value_init (&tmp, G_TYPE_STRING);
+ g_value_transform (value, &tmp);
+ g_value_unset (&tmp);
+}
static void
test_flags_basic (void)
@@ -74,12 +84,11 @@ test_flags_basic (void)
g_value_set_flags (&value, 2|8);
g_assert_cmpint (g_value_get_flags (&value), ==, 2|8);
- g_value_unset (&value);
class = g_type_class_ref (type);
g_assert_cmpint (class->mask, ==, 1|2|8);
- g_assert_cmpint (class->n_values, ==, 3);
+ g_assert_cmpint (class->n_values, ==, 4);
val = g_flags_get_first_value (class, 2|8);
g_assert (val != NULL);
@@ -98,6 +107,9 @@ test_flags_basic (void)
g_assert_cmpint (val->value, ==, 1);
val = g_flags_get_value_by_nick (class, "purple");
g_assert (val == NULL);
+
+ test_flags_transform_to_string (&value);
+ g_value_unset (&value);
}
int
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]