summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2016-05-23 19:51:28 +0200
committerBastien Nocera <hadess@hadess.net>2016-05-23 20:19:36 +0200
commit2dd40cacf5cef92e5bfe241fca34237a3676f887 (patch)
treeeb47afc6cf19c04af18b377d24800c86c0a20db0
parent50779f3368f4d70b28d238fc3fde584074f69bdb (diff)
downloadgnome-bluetooth-2dd40cacf5cef92e5bfe241fca34237a3676f887.tar.gz
settings: Fix warning with unknown vendors
And rework the code to avoid the use of stack allocated memory.
-rw-r--r--lib/pin.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/lib/pin.c b/lib/pin.c
index c5b1d9f7..f07b53f5 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;
}