From ad79b0f8efdb72e9c4b337dffa62521e7fa2a89a Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Sat, 18 Aug 2012 14:14:21 -0400 Subject: [PATCH] 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. --- gio/gmenumodel.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/gio/gmenumodel.c b/gio/gmenumodel.c index d3285fa..47860d2 100644 --- a/gio/gmenumodel.c +++ b/gio/gmenumodel.c @@ -579,6 +579,12 @@ g_menu_model_get_item_attribute_value (GMenuModel *model, * type, then the positional parameters are ignored and %FALSE is * 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 * type * @@ -591,16 +597,20 @@ g_menu_model_get_item_attribute (GMenuModel *model, const gchar *format_string, ...) { - const GVariantType *expected_type; GVariant *value; 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) return FALSE; + if (!g_variant_check_format_string (value, format_string, TRUE)) + { + g_variant_unref (value); + return FALSE; + } + va_start (ap, format_string); g_variant_get_va (value, format_string, NULL, &ap); g_variant_unref (value); -- 2.7.4