Fix handlig for gboolean mce_bt_set field
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 normalization (double negation) in assignment:mce_bt_set = !!(sigvalue & MCE_RADIO_STATE_BLUETOOTH) preserves that "mce_bt_set" will receive only TRUE or FALSE value.
--- plugins/maemo6.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
plugins/maemo6.c +1 -1
@@ -71,7 +71,7 @@ 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 );if (mce_bt_set)btd_adapter_switch_online (adapter);
Signature · 1 line
1.6.3.3
Hi Rafal,
Quoted 13 lines · Rafal Michalski
Expression (sigvalue &
MCE_RADIO_STATE_BLUETOOTH) is invalid because it makes wrong assumption about that it evaluates to TRUE, when bitMCE_RADIO_STATE_BLUETOOTHis set. In this case, assignmentmce_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 normalization (double negation) in assignment:mce_bt_set= !!(sigvalue &MCE_RADIO_STATE_BLUETOOTH) preserves that "mce_bt_set" will receive only TRUE or FALSE value.
Quoted 3 lines
--- plugins/maemo6.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
Thanks. The patch has been pushed upstream with a much simplified commit message (the above is really quite complicated to read compared to the simplicity of the actual fix).
Johan