From 12ada441567a48f0aacf4c0d3d42e46fbf956917 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 7 Sep 2021 11:14:32 +0200 Subject: libmm-glib,simple-status: avoid shadowing 'properties' variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ../libmm-glib/mm-simple-status.c: In function ‘mm_simple_status_new_from_dictionary’: ../libmm-glib/mm-simple-status.c:426:21: warning: declaration of ‘properties’ shadows a global declaration [-Wshadow] 426 | MMSimpleStatus *properties; | ^~~~~~~~~~ ../libmm-glib/mm-simple-status.c:55:20: note: shadowed declaration is here 55 | static GParamSpec *properties[PROP_LAST]; | ^~~~~~~~~~ --- libmm-glib/mm-simple-status.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'libmm-glib/mm-simple-status.c') diff --git a/libmm-glib/mm-simple-status.c b/libmm-glib/mm-simple-status.c index ff52ffe9..cc805a9e 100644 --- a/libmm-glib/mm-simple-status.c +++ b/libmm-glib/mm-simple-status.c @@ -419,15 +419,16 @@ MMSimpleStatus * mm_simple_status_new_from_dictionary (GVariant *dictionary, GError **error) { - GError *inner_error = NULL; - GVariantIter iter; - gchar *key; - GVariant *value; - MMSimpleStatus *properties; + GError *inner_error = NULL; + GVariantIter iter; + gchar *key; + GVariant *value; + g_autoptr(MMSimpleStatus) props = NULL; + + props = mm_simple_status_new (); - properties = mm_simple_status_new (); if (!dictionary) - return properties; + return g_steal_pointer (&props); if (!g_variant_is_of_type (dictionary, G_VARIANT_TYPE ("a{sv}"))) { g_set_error (error, @@ -435,13 +436,11 @@ mm_simple_status_new_from_dictionary (GVariant *dictionary, MM_CORE_ERROR_INVALID_ARGS, "Cannot create Simple status from dictionary: " "invalid variant type received"); - g_object_unref (properties); return NULL; } g_variant_iter_init (&iter, dictionary); - while (!inner_error && - g_variant_iter_next (&iter, "{sv}", &key, &value)) { + while (!inner_error && g_variant_iter_next (&iter, "{sv}", &key, &value)) { /* Note: we could do a more efficient matching by checking the variant type * and just g_object_set()-ing they specific 'key' and value, but we do want * to check which input keys we receive, in order to propagate the error. @@ -454,19 +453,19 @@ mm_simple_status_new_from_dictionary (GVariant *dictionary, g_str_equal (key, MM_SIMPLE_PROPERTY_CDMA_SID) || g_str_equal (key, MM_SIMPLE_PROPERTY_CDMA_NID)) { /* uint properties */ - g_object_set (properties, + g_object_set (props, key, g_variant_get_uint32 (value), NULL); } else if (g_str_equal (key, MM_SIMPLE_PROPERTY_3GPP_OPERATOR_CODE) || g_str_equal (key, MM_SIMPLE_PROPERTY_3GPP_OPERATOR_NAME)) { /* string properties */ - g_object_set (properties, + g_object_set (props, key, g_variant_get_string (value, NULL), NULL); } else if (g_str_equal (key, MM_SIMPLE_PROPERTY_CURRENT_BANDS) || g_str_equal (key, MM_SIMPLE_PROPERTY_SIGNAL_QUALITY)) { /* remaining complex types, as variant */ - g_object_set (properties, + g_object_set (props, key, value, NULL); } else { @@ -484,11 +483,10 @@ mm_simple_status_new_from_dictionary (GVariant *dictionary, /* If error, destroy the object */ if (inner_error) { g_propagate_error (error, inner_error); - g_object_unref (properties); - properties = NULL; + return NULL; } - return properties; + return g_steal_pointer (&props); } /*****************************************************************************/ -- cgit v1.2.3-70-g09d2