mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-12 23:46:17 +01:00
Special-case pointer-sized value types
GValues containing pointer-sized things can hold a NULL value, and various transformation functions in the wild are not NULL safe. Fixes: #457 See also: https://gitlab.gnome.org/GNOME/mutter/-/issues/2625
This commit is contained in:
parent
650090eefb
commit
92bbb0033b
53
gdump.c
53
gdump.c
@ -119,6 +119,27 @@ invoke_error_quark (GModule *self, const char *symbol, GError **error)
|
||||
return sym ();
|
||||
}
|
||||
|
||||
static char *
|
||||
value_transform_to_string (const GValue *value)
|
||||
{
|
||||
GValue tmp = G_VALUE_INIT;
|
||||
char *s = NULL;
|
||||
|
||||
g_value_init (&tmp, G_TYPE_STRING);
|
||||
|
||||
if (g_value_transform (value, &tmp))
|
||||
{
|
||||
const char *str = g_value_get_string (&tmp);
|
||||
|
||||
if (str != NULL)
|
||||
s = g_strescape (str, NULL);
|
||||
}
|
||||
|
||||
g_value_unset (&tmp);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* A simpler version of g_strdup_value_contents(), but with stable
|
||||
* output and less complex semantics
|
||||
*/
|
||||
@ -137,24 +158,34 @@ value_to_string (const GValue *value)
|
||||
|
||||
return g_strescape (s, NULL);
|
||||
}
|
||||
else if (g_value_type_transformable (G_VALUE_TYPE (value), G_TYPE_STRING))
|
||||
else
|
||||
{
|
||||
GValue tmp = G_VALUE_INIT;
|
||||
char *s = NULL;
|
||||
GType value_type = G_VALUE_TYPE (value);
|
||||
|
||||
g_value_init (&tmp, G_TYPE_STRING);
|
||||
switch (G_TYPE_FUNDAMENTAL (value_type))
|
||||
{
|
||||
case G_TYPE_BOXED:
|
||||
if (g_value_get_boxed (value) == NULL)
|
||||
return NULL;
|
||||
else
|
||||
return value_transform_to_string (value);
|
||||
break;
|
||||
|
||||
if (g_value_transform (value, &tmp))
|
||||
s = g_strescape (g_value_get_string (&tmp), NULL);
|
||||
case G_TYPE_OBJECT:
|
||||
if (g_value_get_object (value) == NULL)
|
||||
return NULL;
|
||||
else
|
||||
return value_transform_to_string (value);
|
||||
break;
|
||||
|
||||
g_value_unset (&tmp);
|
||||
|
||||
if (s == NULL)
|
||||
case G_TYPE_POINTER:
|
||||
return NULL;
|
||||
|
||||
return s;
|
||||
default:
|
||||
return value_transform_to_string (value);
|
||||
}
|
||||
else
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user