[PATCH] Infinite loop/always true check possible with unsigned counter.

Felix Domke tmbinc at elitedvb.net
Tue Jul 10 10:41:21 EST 2007


Paul Mackerras wrote:
>> Fix to correct a possible infinite loop or an always true check when the 
>> unsigned long counter "i" is used in
>> lmb_add_region() in the following for loop:
>> for (i = rgn->cnt-1; i >= 0; i--)
> Unfortunately this won't fix the bug.  Since rgn->cnt is unsigned
> long, the comparison will be done as an unsigned comparison even if i
> is signed.
> Instead, change the loop to go from rgn->cnt down to 1, and in the
> loop body, change all instances of "i+1" to "i", and "i" to "i-1".
What's about

i = rgn->cnt;
while (i--)
...
?

(or  for (i=rgn->cnt; i--; ), if you want a for-loop)


Felix



More information about the Linuxppc-dev mailing list