[glib/wip/menuitem-api: 2/4] GMenuModel: remove a type safety bug
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/menuitem-api: 2/4] GMenuModel: remove a type safety bug
- Date: Sat, 18 Aug 2012 21:46:05 +0000 (UTC)
commit b6d0d4a376911c1437716b720a4c25430c6eb251
Author: Ryan Lortie <desrt desrt ca>
Date: Sat Aug 18 14:14:21 2012 -0400
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 files 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]