Skip to contentSkip to conversation

Fix handlig for gboolean mce_bt_set field

PATCH In review Rafal Michalski 3 participants 3 messages Sep 30, 2010 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix handlig for gboolean mce_bt_set field

Expression (sigvalue & MCE_RADIO_STATE_BLUETOOTH) is invalid because it makes wrong assumption about that it evaluates to TRUE, when bit MCE_RADIO_STATE_BLUETOOTH is set. In this case, assignment mce_bt_set = (sigvalue & MCE_RADIO_STATE_BLUETOOTH) makes that gboolean "mce_bt_set" receives value equal 8 instead of TRUE (equal 1). So condition in "if (mce_bt_set == powered)" statement will never evaluate to true because gboolean "powered" receives only TRUE (equal 1) or FALSE (equal 0) value. We should remember that gboolean type is not bool type in C++ sense. It's simply typedef of gint (int), so assignmnet:
mce_bt_set = (sigvalue & MCE_RADIO_STATE_BLUETOOTH) is valid for compiler but in our case it makes a bug. So assignmnet:
mce_bt_set = (sigvalue & MCE_RADIO_STATE_BLUETOOTH) == MCE_RADIO_STATE_BLUETOOTH preserves that "mce_bt_set" will receive only TRUE or FALSE value.

---
 plugins/maemo6.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
plugins/maemo6.c +2 -1
index c96731d..45d96b8 100644
@@ -71,7 +71,8 @@ static gboolean mce_signal_callback(DBusConnection *connection,
 
 		/* set the adapter according to the mce signal
 		   and remember the value */
-		mce_bt_set = sigvalue & MCE_RADIO_STATE_BLUETOOTH;
+		mce_bt_set = (sigvalue & MCE_RADIO_STATE_BLUETOOTH) ==
+						MCE_RADIO_STATE_BLUETOOTH;
 
 		if (mce_bt_set)
 			btd_adapter_switch_online(adapter);
Signature · 1 line
1.6.3.3
#1 lore raw

Hi Rafal,

Quoted 22 lines · Rafal Michalski

Expression (sigvalue & MCE_RADIO_STATE_BLUETOOTH) is invalid because it makes wrong assumption about that it evaluates to TRUE, when bit MCE_RADIO_STATE_BLUETOOTH is set. In this case, assignment mce_bt_set = (sigvalue & MCE_RADIO_STATE_BLUETOOTH) makes that gboolean "mce_bt_set" receives value equal 8 instead of TRUE (equal 1). So condition in "if (mce_bt_set == powered)" statement will never evaluate to true because gboolean "powered" receives only TRUE (equal 1) or FALSE (equal 0) value. We should remember that gboolean type is not bool type in C++ sense. It's simply typedef of gint (int), so assignmnet:
mce_bt_set = (sigvalue & MCE_RADIO_STATE_BLUETOOTH) is valid for compiler but in our case it makes a bug. So assignmnet:
mce_bt_set = (sigvalue & MCE_RADIO_STATE_BLUETOOTH) == MCE_RADIO_STATE_BLUETOOTH preserves that "mce_bt_set" will receive only TRUE or FALSE value.

---
 plugins/maemo6.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
plugins/maemo6.c +0 -0
index c96731d..45d96b8 100644

plugins/maemo6.c static gboolean mce_signal_callback(DBusConnection *connection, · line 75

Quoted 6 lines
plugins/maemo6.c +2 -1
@@ -71,7 +71,8 @@ static gboolean mce_signal_callback(DBusConnection *connection,
 
 		/* set the adapter according to the mce signal
 		   and remember the value */
-		mce_bt_set = sigvalue & MCE_RADIO_STATE_BLUETOOTH;
+		mce_bt_set = (sigvalue & MCE_RADIO_STATE_BLUETOOTH) ==
+						MCE_RADIO_STATE_BLUETOOTH;

Alternatively you can do
mce_bt_set = !!(sigvalue & MCE_RADIO_STATE_BLUETOOTH)

It might be better do that this way, but I'm not really asking you to change that. ;)

Signature · 2 lines
Gustavo F. Padovan
ProFUSION embedded systems - http://profusion.mobi
#2 lore raw
Quoted 6 lines · Gustavo F. Padovan
Quoted 6 lines
plugins/maemo6.c +0 -0
index c96731d..45d96b8 100644
@@ -71,7 +71,8 @@ static gboolean mce_signal_callback(DBusConnection *connection,
 
Quoted 8 lines
Quoted 5 lines
plugins/maemo6.c +0 -0
               /* set the adapter according to the mce signal

                 and remember the value */
-             mce_bt_set = sigvalue & MCE_RADIO_STATE_BLUETOOTH;
+             mce_bt_set = (sigvalue & MCE_RADIO_STATE_BLUETOOTH) ==
+                                             MCE_RADIO_STATE_BLUETOOTH;

Alternatively you can do
       mce_bt_set = !!(sigvalue & MCE_RADIO_STATE_BLUETOOTH)

I'm a bit late, but:

mce_bt_set = (sigvalue & MCE_RADIO_STATE_BLUETOOTH) != 0;

would equally work.

PS: yes, I know it's already commited. :). Interestingly, there is only one more occurrence of this idiom already in bluez code:

input/device.c: connected = !!g_slist_find_custom(idev->connections, NULL,

Regards,

Signature · 3 lines
Anderson Lizardo
OpenBossa Labs - INdT
Manaus - Brazil