Closed Bug 206864 Opened 22 years ago Closed 22 years ago

Incorrect comparison in content/html/style/src/nsCSSParser.cpp

Categories

(Core :: CSS Parsing and Computation, defect)

x86
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: tenthumbs, Assigned: bzbarsky)

References

Details

Attachments

(1 file, 2 obsolete files)

Gcc says: nsCSSParser.cpp:2780: warning: comparison of unsigned expression < 0 is always false and the code is: 2773 PRUint32 value = (PRUint32)NSToIntRound(mToken.mNumber*255); 2774 2775 if (!ExpectSymbol(aErrorCode, ')', PR_TRUE)) { 2776 REPORT_UNEXPECTED_TOKEN(NS_LITERAL_STRING("Expected ')' but found")); 2777 return PR_FALSE; 2778 } 2779 2780 if (value < 0) value = 0; 2781 if (value > 255) value = 255; 2782 aOpacity = (PRUint8)value; AS it stands a negative number becomes 255 not 0. Assuming you want to catch negative values, then "value" must be signed. I suggest making it just an int. The native type is, presumably, the most efficient. Assigning it to bz because he did it in bug 160550.
Attached patch simple patch (obsolete) — Splinter Review
How about PRInt32 instead of int?
What about a 64-bit platform? Using 32-bit quantities may incur additional overhead. It all depends on the instruction set. I generally prefer to let the compiler writers deal with this sort of stuff.
I wouldn't call nsUnitConversion.h a shining model of good coding practice. See bug 118117 for one way it's broken. It was also created essentially at the dawn of time (mozilla-wise). The code might well be derived from an earlier source. Since it uses IEEE floats which have just 24 bits of precision, perhaps PRInt32 is just to force something larger than that. Since mozilla always runs on at least a 32-bit platform forcing a special type seems useless to me. However, I realize I'm probably alone in my views so I'll just hold my nose while you use PRInt32. The important thing is to use a signed quantity.
It doesn't matter what you or I think of nsUnitConversion -- you're calling that function, and it returns a PRInt32. So in this case, on a 64-bit platform, it's assigning to an 'int' that may have additional overhead. And on platforms where an 'int' is less than 32 bits, you could overflow an 'int' if you assigned out of a PRInt32 into it. So let's not do that, ok? ;) In any case, if you could post an updated patch that would be great, because I have no tree to diff against.
Well, mozilla isn't supposed to run on a 16-bit platform so I don't think that's relevant. I have to rant a little. I see pepple running around becoming upset because of millisecond run-time changes. I see other people insisting on specifying object types (e.g. 8 and 16 bit integers) that have performance penalties. Yet, the complainers never mention the obvious. Anyway, stand by for the patch.
Attached patch PRInt32 patch (obsolete) — Splinter Review
Attachment #124063 - Attachment is obsolete: true
Attachment #124209 - Attachment is obsolete: true
Comment on attachment 124210 [details] [diff] [review] the right patch, this time r+sr=bzbarsky; please find someone to check this in? (eg biesi or timeless, maybe?)
Attachment #124210 - Flags: superreview+
Attachment #124210 - Flags: review+
ok, done: Checking in mozilla/content/html/style/src/nsCSSParser.cpp; /cvsroot/mozilla/content/html/style/src/nsCSSParser.cpp,v <-- nsCSSParser.cpp new revision: 3.223; previous revision: 3.222 done
Status: NEW → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
*** Bug 223391 has been marked as a duplicate of this bug. ***
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: