OSDN Git Service

Fix device->name checks
authorJohan Hedberg <johan.hedberg@nokia.com>
Tue, 30 Jun 2009 12:02:48 +0000 (15:02 +0300)
committerJohan Hedberg <johan.hedberg@nokia.com>
Tue, 30 Jun 2009 12:04:53 +0000 (15:04 +0300)
btd_device->name is defined as "char name[248];" so checking for
device->name will always be true. Instead check for the string length
where it makes sense.

This patch maintains the previous behavior in that the Name property is
included in the GetProperties reply even if it's empty.

src/device.c

index a35bb7d..f4746a2 100644 (file)
@@ -302,22 +302,19 @@ static DBusMessage *get_properties(DBusConnection *conn,
        adapter_get_address(adapter, &src);
        ba2str(&src, srcaddr);
 
-       if (device->name) {
-               ptr = device->name;
-               dict_append_entry(&dict, "Name", DBUS_TYPE_STRING, &ptr);
-       }
+       ptr = device->name;
+       dict_append_entry(&dict, "Name", DBUS_TYPE_STRING, &ptr);
 
        /* Alias (fallback to name or address) */
        if (read_device_alias(srcaddr, dstaddr, name, sizeof(name)) < 1) {
-               if (!ptr) {
+               if (strlen(ptr) == 0) {
                        g_strdelimit(dstaddr, ":", '-');
                        ptr = dstaddr;
                }
        } else
                ptr = name;
 
-       if (ptr)
-               dict_append_entry(&dict, "Alias", DBUS_TYPE_STRING, &ptr);
+       dict_append_entry(&dict, "Alias", DBUS_TYPE_STRING, &ptr);
 
        /* Class */
        if (read_remote_class(&src, &device->bdaddr, &class) == 0) {