All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Error should be returned instead of unnecessary dict_append_array()
@ 2010-12-14 14:20 Pawel Wieczorkiewicz
  2010-12-14 14:44 ` Johan Hedberg
  0 siblings, 1 reply; 2+ messages in thread
From: Pawel Wieczorkiewicz @ 2010-12-14 14:20 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Pawel Wieczorkiewicz

If there are no adapter up and running, there would be
no elements to be added using dict_append_array(). We
should return DBus error ".DoesNotExist", rather than
appending NULL pointer and zero elements.

On behalf of ST-Ericsson SA
---
 src/manager.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/src/manager.c b/src/manager.c
index c8ec7e5..9060180 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -185,12 +185,21 @@ static DBusMessage *get_properties(DBusConnection *conn,
 		array[i] = (char *) adapter_get_path(adapter);
 		i++;
 	}
+
+	if (!i)
+		goto error;
+
 	dict_append_array(&dict, "Adapters", DBUS_TYPE_OBJECT_PATH, &array, i);
 	g_free(array);
 
 	dbus_message_iter_close_container(&iter, &dict);
 
 	return reply;
+
+error:
+	g_free(array);
+	g_free(reply);
+	return g_dbus_create_error(msg, ERROR_INTERFACE ".DoesNotExist", "Adapter does not exist");
 }
 
 static GDBusMethodTable manager_methods[] = {
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Error should be returned instead of unnecessary dict_append_array()
  2010-12-14 14:20 [PATCH] Error should be returned instead of unnecessary dict_append_array() Pawel Wieczorkiewicz
@ 2010-12-14 14:44 ` Johan Hedberg
  0 siblings, 0 replies; 2+ messages in thread
From: Johan Hedberg @ 2010-12-14 14:44 UTC (permalink / raw)
  To: Pawel Wieczorkiewicz; +Cc: linux-bluetooth

Hi Pawel,

On Tue, Dec 14, 2010, Pawel Wieczorkiewicz wrote:
> If there are no adapter up and running, there would be
> no elements to be added using dict_append_array(). We
> should return DBus error ".DoesNotExist", rather than
> appending NULL pointer and zero elements.
> 
> On behalf of ST-Ericsson SA
> ---
>  src/manager.c |    9 +++++++++
>  1 files changed, 9 insertions(+), 0 deletions(-)

Nack. Manager.GetProperties shouldn't fail if there no adapters. There
will be more properties coming in the future (a "DefaultAdapter"
property for sure) and could either have an empty array for the Adapters
or just leave out that key from the dictionary (i.e. in the worst case
we've got an empty dictionary, but that's fine too imho).

Johan

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-12-14 14:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-14 14:20 [PATCH] Error should be returned instead of unnecessary dict_append_array() Pawel Wieczorkiewicz
2010-12-14 14:44 ` Johan Hedberg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.