Logic error in the code

Bug #1071757 reported by Albert Astals Cid
6
This bug affects 1 person
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

Revision history for this message
Charles Kerr (charlesk) wrote :

Very fast catch; thank you :)

Changed in indicator-power:
status: New → In Progress
assignee: nobody → Charles Kerr (charlesk)
milestone: none → 12.10.4
Changed in indicator-power:
status: In Progress → Fix Committed
Changed in indicator-power:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.