Closed Bug 221292 Opened 21 years ago Closed 21 years ago

Test for unsigned >=0 in mozilla/content/events/src/nsEventStateManager.cpp

Categories

(Core :: DOM: Events, defect)

x86
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: tenthumbs, Unassigned)

Details

Attachments

(1 file)

Gcc says:

nsEventStateManager.cpp:3581: warning: \
 comparison of unsigned expression >= 0 is always true

Code is:

3579  PRInt32 increment = forward ? 1 : - 1;
3580  PRInt32 start = index < count ? index + increment : (forward ? 0 : count - 1);
3581  for (index = start; index < count && index >= 0; index += increment) {
3582  //Iterate over the children.

I don't understand what's supposed to happen but (index >= 0) == 1 seems like a
bad thing.
I think the index >= 0 can just be struck.  It looks like it's supposed to
terminate the loop in the backwards case.  But since index will be MAXINT when
the loop should terminate, that means index >= count and the first test will
catch it.  Should probably have |PRUint32 start| though.
Yeah, it does look like the >= 0 check can just be removed, and a comment to
that effect added. Jst?  Thoughts?
I agree with Nick, the "index >= 0" test can be removed.
"start" can be eliminated too:

3580  index = index < count ? index + increment : (forward ? 0 : count - 1);
3581  for (; index < count; index += increment) {

Please also remove the space between the minus and 1 on line 3579.
Could someone attach a patch, then?  I can hardly review my own patch... ;)
Attachment #132698 - Flags: review?(bzbarsky)
Tested by tabbing back and forth over an image map with zero or more areas.
Just to be sure ;)
Comment on attachment 132698 [details] [diff] [review]
Patch rev. 1

r+sr=bzbarsky
Attachment #132698 - Flags: superreview+
Attachment #132698 - Flags: review?(bzbarsky)
Attachment #132698 - Flags: review+
Changed "follwing" to "following" and checked in.
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: