[gnome-bluetooth] settings: Fix warning with unknown vendors



commit 2dd40cacf5cef92e5bfe241fca34237a3676f887
Author: Bastien Nocera <hadess hadess net>
Date:   Mon May 23 19:51:28 2016 +0200

    settings: Fix warning with unknown vendors
    
    And rework the code to avoid the use of stack allocated memory.

 lib/pin.c |   34 ++++++++++++++++++----------------
 1 files changed, 18 insertions(+), 16 deletions(-)
---
diff --git a/lib/pin.c b/lib/pin.c
index c5b1d9f..f07b53f 100644
--- a/lib/pin.c
+++ b/lib/pin.c
@@ -175,11 +175,11 @@ get_pincode_for_device (guint       type,
 {
        GMarkupParseContext *ctx;
        GMarkupParser parser = { pin_db_parse_start_tag, NULL, NULL, NULL, NULL };
-       PinParseData data;
+       PinParseData *data;
        char *buf;
        gsize buf_len;
        GError *err = NULL;
-       char *tmp_vendor;
+       char *tmp_vendor, *ret_pin;
 
        g_return_val_if_fail (address != NULL, NULL);
 
@@ -199,18 +199,18 @@ get_pincode_for_device (guint       type,
                g_free (filename);
        }
 
-       data.ret_pin = NULL;
-       data.max_digits = 0;
-       data.type = type;
-       data.address = address;
-       data.name = name;
-       data.confirm = TRUE;
+       data = g_new0 (PinParseData, 1);
+       data->type = type;
+       data->address = address;
+       data->name = name;
+       data->confirm = TRUE;
 
        tmp_vendor = oui_to_vendor (address);
-       data.vendor = g_ascii_strdown (tmp_vendor, -1);
+       if (tmp_vendor)
+               data->vendor = g_ascii_strdown (tmp_vendor, -1);
        g_free (tmp_vendor);
 
-       ctx = g_markup_parse_context_new (&parser, 0, &data, NULL);
+       ctx = g_markup_parse_context_new (&parser, 0, data, NULL);
 
        if (!g_markup_parse_context_parse (ctx, buf, buf_len, &err)) {
                g_warning ("Failed to parse '%s': %s\n", PIN_CODE_DB, err->message);
@@ -221,16 +221,18 @@ get_pincode_for_device (guint       type,
        g_free (buf);
 
        if (max_digits != NULL)
-               *max_digits = data.max_digits;
+               *max_digits = data->max_digits;
        if (confirm != NULL)
-               *confirm = data.confirm;
+               *confirm = data->confirm;
 
        g_debug ("Got pin '%s' (max digits: %d, confirm: %d) for device '%s' (type: %s address: %s, vendor: 
%s)",
-                data.ret_pin, data.max_digits, data.confirm,
-                name ? name : "", bluetooth_type_to_string (type), address, data.vendor);
+                data->ret_pin, data->max_digits, data->confirm,
+                name ? name : "", bluetooth_type_to_string (type), address, data->vendor);
 
-       g_free (data.vendor);
+       g_free (data->vendor);
+       ret_pin = data->ret_pin;
+       g_free (data);
 
-       return data.ret_pin;
+       return ret_pin;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]