mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-14 04:57:46 +02:00
GMenuModel: remove a type safety bug
There was a /* XXX */ in the code here to do proper typechecking of the GVariant in the menu model when using g_menu_model_get_item_attribute(). We have g_variant_check_format_string() now, so use it.
This commit is contained in:
@@ -579,6 +579,12 @@ g_menu_model_get_item_attribute_value (GMenuModel *model,
|
|||||||
* type, then the positional parameters are ignored and %FALSE is
|
* type, then the positional parameters are ignored and %FALSE is
|
||||||
* returned.
|
* returned.
|
||||||
*
|
*
|
||||||
|
* This function is a mix of g_menu_model_get_item_attribute_value() and
|
||||||
|
* g_variant_get(), followed by a g_variant_unref(). As such,
|
||||||
|
* @format_string must make a complete copy of the data (since the
|
||||||
|
* #GVariant may go away after the call to g_variant_unref()). In
|
||||||
|
* particular, no '&' characters are allowed in @format_string.
|
||||||
|
*
|
||||||
* Returns: %TRUE if the named attribute was found with the expected
|
* Returns: %TRUE if the named attribute was found with the expected
|
||||||
* type
|
* type
|
||||||
*
|
*
|
||||||
@@ -591,16 +597,20 @@ g_menu_model_get_item_attribute (GMenuModel *model,
|
|||||||
const gchar *format_string,
|
const gchar *format_string,
|
||||||
...)
|
...)
|
||||||
{
|
{
|
||||||
const GVariantType *expected_type;
|
|
||||||
GVariant *value;
|
GVariant *value;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
expected_type = NULL; /* XXX devine the type, ensure no '&' */
|
value = g_menu_model_get_item_attribute_value (model, item_index, attribute, NULL);
|
||||||
|
|
||||||
value = g_menu_model_get_item_attribute_value (model, item_index, attribute, expected_type);
|
|
||||||
if (value == NULL)
|
if (value == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
if (!g_variant_check_format_string (value, format_string, TRUE))
|
||||||
|
{
|
||||||
|
g_variant_unref (value);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
va_start (ap, format_string);
|
va_start (ap, format_string);
|
||||||
g_variant_get_va (value, format_string, NULL, &ap);
|
g_variant_get_va (value, format_string, NULL, &ap);
|
||||||
g_variant_unref (value);
|
g_variant_unref (value);
|
||||||
|
Reference in New Issue
Block a user