Logic error in the code
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
indicator-power |
Fix Released
|
Undecided
|
Charles Kerr |
Bug Description
Found by clang static analyzer
in
static gint compare_func (gconstpointer ga, gconstpointer gb)
there is some code that says
if (b_state != state) /* a is charging */
{
ret = 1;
}
if (a_state != state) /* b is charging */
{
ret = -1;
}
else /* both are discharging; most-time-to-charge goes first */
{
if (!a_time || !b_time) /* known time always trumps unknown time */
ret = a_time ? -1 : 1;
else if (a_time != b_time)
ret = a_time > b_time ? -1 : 1;
else
ret = a_percentage < b_percentage ? -1 : 1;
}
As you can see the first "if (b_state != state)" is 'useless' as the second if assigns ret all the time, both in the true branch and in the else branch, so either it has to be removed or if the calculation is indeed useful the second ifs/elses have to be tweaked
Related branches
- Lars Karlitski (community): Approve
- PS Jenkins bot (community): Approve (continuous-integration)
-
Diff: 217 lines (+80/-56)2 files modifiedsrc/indicator-power.c (+4/-4)
tests/test-device.cc (+76/-52)
Changed in indicator-power: | |
status: | In Progress → Fix Committed |
Changed in indicator-power: | |
status: | Fix Committed → Fix Released |
Very fast catch; thank you :)