2006-03-14 Matthias Clasen <mclasen@redhat.com>
+ * glib/gutils.c (g_parse_debug_string): Don't read past the
+ end of the string. (#334471, Morten Welinder)
+
+ * tests/testglib.c (test_g_parse_debug_string): Add testss
+ for g_parse_debug_string.
+
* glib/goption.c (parse_short_option): Don't create the
option_name twice. (#334519, Chris Wilson)
2006-03-14 Matthias Clasen <mclasen@redhat.com>
+ * glib/gutils.c (g_parse_debug_string): Don't read past the
+ end of the string. (#334471, Morten Welinder)
+
+ * tests/testglib.c (test_g_parse_debug_string): Add testss
+ for g_parse_debug_string.
+
* glib/goption.c (parse_short_option): Don't create the
option_name twice. (#334519, Chris Wilson)
2006-03-14 Matthias Clasen <mclasen@redhat.com>
+ * glib/gutils.c (g_parse_debug_string): Don't read past the
+ end of the string. (#334471, Morten Welinder)
+
+ * tests/testglib.c (test_g_parse_debug_string): Add testss
+ for g_parse_debug_string.
+
* glib/goption.c (parse_short_option): Don't create the
option_name twice. (#334519, Chris Wilson)
{
const gchar *p = string;
const gchar *q;
- gboolean done = FALSE;
- while (*p && !done)
+ while (*p)
{
q = strchr (p, ':');
if (!q)
- {
- q = p + strlen(p);
- done = TRUE;
- }
+ q = p + strlen(p);
- for (i=0; i<nkeys; i++)
+ for (i = 0; i < nkeys; i++)
if (g_ascii_strncasecmp (keys[i].key, p, q - p) == 0 &&
keys[i].key[q - p] == '\0')
result |= keys[i].value;
- p = q + 1;
+ p = q;
+ if (*p == ':')
+ p++;
}
}
return TRUE;
}
+static void
+test_g_parse_debug_string (void)
+{
+ GDebugKey keys[3] = {
+ { "foo", 1 },
+ { "bar", 2 },
+ { "baz", 4 }
+ };
+ guint n_keys = 3;
+ guint result;
+
+ result = g_parse_debug_string ("bar:foo:blubb", keys, n_keys);
+ g_assert (result == 3);
+
+ result = g_parse_debug_string (":baz::_E@~!_::", keys, n_keys);
+ g_assert (result == 4);
+
+ result = g_parse_debug_string ("", keys, n_keys);
+ g_assert (result == 0);
+
+ result = g_parse_debug_string (" : ", keys, n_keys);
+ g_assert (result == 0);
+}
+
+
int
main (int argc,
char *argv[])
close (fd);
g_clear_error (&error);
remove (name_used);
-
+
+ test_g_parse_debug_string ();
+
return 0;
}