Closed Bug 660693 Opened 14 years ago Closed 14 years ago

Comparison between signed and unsigned integer expressions in nsAccessible.h

Categories

(Core :: Disability Access APIs, defect)

x86
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla7

People

(Reporter: jdm, Assigned: tbsaunde)

References

(Blocks 1 open bug)

Details

(Whiteboard: [build_warning])

Attachments

(1 file, 2 obsolete files)

../../../dist/include/nsAccessible.h: In member function ‘bool nsAccessible::IsChildrenFlag(nsAccessible::ChildrenFlags) const’: ../../../dist/include/nsAccessible.h:521: warning: comparison between signed and unsigned integer expressions
520 inline bool IsChildrenFlag(ChildrenFlags aFlag) const 521 { return (mFlags & kChildrenFlagsMask) == aFlag; }
Attached patch patch (obsolete) — Splinter Review
Attachment #536184 - Flags: review?(surkov.alexander)
Blocks: cleana11y
Should we also change PRUint32 mFlags; to PRInt32 mFlags; ?
Comment on attachment 536184 [details] [diff] [review] patch I'm not sure we need to do that, but I don't see a reason not to make it a PRInt32 and that seems safer so I'll do that.
Attachment #536184 - Flags: review?(surkov.alexander)
(In reply to comment #4) > Comment on attachment 536184 [details] [diff] [review] [review] > patch What exactly makes a warning?
(In reply to comment #5) > (In reply to comment #4) > > Comment on attachment 536184 [details] [diff] [review] [review] [review] > > patch > > What exactly makes a warning? I think gcc is representing variables of the enum type as signed integers, which although my check was brief doesn't seem to be contrairy to the spec.
we shouldn't rely on enum as signed or unsigned int, we should deal with it as with type (in our case ChildrenFlags), so if we get failures (because there's no autocasting) then we should do explicit casting I think.
(In reply to comment #7) > we shouldn't rely on enum as signed or unsigned int, we should deal with it > as with type (in our case ChildrenFlags), so if we get failures (because > there's no autocasting) then we should do explicit casting I think. I believe the spec says that a signed integer should always work, and unsidgned is fine but the implementation may warn about it, using signed int as the type of kChildrenFlags and mFlags is always fine. However I don't think there's any technical issue with that approach if you want to use it.
(In reply to comment #8) > using signed > int as the type of kChildrenFlags and mFlags is always fine. it's not good idea to use signed int for something that can't ever be signed.
(In reply to comment #9) > (In reply to comment #8) > > > using signed > > int as the type of kChildrenFlags and mFlags is always fine. > > it's not good idea to use signed int for something that can't ever be signed. sure, ideally we'd only use a 2 bit wide integer here, but that doesn't exist.
On the other hand enum foo { eFoo1 = 0, eFoo2 = 1, eFoo3 = 2}; is a little odd, and I'd be tempted to use const int foo1 = 0 ... here instead.
(In reply to comment #11) > On the other hand enum foo { eFoo1 = 0, eFoo2 = 1, eFoo3 = 2}; is a little > odd, and I'd be tempted to use const int foo1 = 0 ... here instead. what's odd having a type for that?
(In reply to comment #12) > (In reply to comment #11) > > On the other hand enum foo { eFoo1 = 0, eFoo2 = 1, eFoo3 = 2}; is a little > > odd, and I'd be tempted to use const int foo1 = 0 ... here instead. > > what's odd having a type for that? I'm not really sure, I think it mostly has to do with the meaning of the word enumerate. To Me a enum type is a type where a value will have one of a set. of values at a time, and not b the combination of several values.
(In reply to comment #13) > > what's odd having a type for that? > > I'm not really sure, I think it mostly has to do with the meaning of the > word enumerate. To Me a enum type is a type where a value will have one of > a set. of values at a time, and not b the combination of several values. correct, that's what happens for ChildrenFlags, mFlags is never used to keep several flags from ChildrenFlags.
Attached patch patch2 (obsolete) — Splinter Review
once we've anded the non children flags bits off of mFlags we should have a valid ChildrenFlags enum so lets cast to that.
Attachment #536184 - Attachment is obsolete: true
Attachment #536407 - Flags: review?(surkov.alexander)
Comment on attachment 536407 [details] [diff] [review] patch2 use static_cast over implicit casting
Attachment #536407 - Flags: review?(surkov.alexander) → review+
Attached patch updated patchSplinter Review
use static_cast<ChildrenFlags>
Attachment #536407 - Attachment is obsolete: true
Comment on attachment 536678 [details] [diff] [review] updated patch Looks right. C++ style casting always preferred.
Attachment #536678 - Flags: review+
Attachment #536678 - Flags: review?(surkov.alexander)
Attachment #536678 - Flags: review?(surkov.alexander)
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → INVALID
WELL, THIS SHOULD BE FIXED, BUT BUG 661392 =[
Resolution: INVALID → FIXED
Assignee: nobody → trev.saunders
Target Milestone: --- → mozilla7
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: