The default bug view has changed. See this FAQ.

Build warnings in FrameLayerBuilder.cpp: "warning: comparison between signed and unsigned integer expressions [-Wsign-compare]", " warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]"

RESOLVED FIXED in mozilla15

Status

()

Core
Graphics
RESOLVED FIXED
5 years ago
5 years ago

People

(Reporter: dholbert, Assigned: nrc)

Tracking

(Blocks: 1 bug)

Trunk
mozilla15
x86_64
Linux
Points:
---
Dependency tree / graph
Bug Flags:
in-testsuite -

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment, 2 obsolete attachments)

(Reporter)

Description

5 years ago
Bug 716439 added 2 new build warnings in FrameLayerBuilder.cpp:
{
../../../mozilla/layout/base/FrameLayerBuilder.cpp: In member function 'void mozilla::{anonymous}::ContainerState::ThebesLayerData::UpdateCommonClipCount(const mozilla::FrameLayerBuilder::Clip&)':
../../../mozilla/layout/base/FrameLayerBuilder.cpp:1154:56: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
../../../mozilla/layout/base/FrameLayerBuilder.cpp: In member function 'void mozilla::FrameLayerBuilder::Clip::ApplyRoundedRectsTo(gfxContext*, PRInt32, PRUint32, PRUint32) const':
../../../mozilla/layout/base/FrameLayerBuilder.cpp:2651:24: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]
}

Both of these are in assertions, indicating that we might not be checking what we think we're checking in those cases.

(I'm building w/ GCC 4.6.3)
(Assignee)

Comment 1

5 years ago
I checked the code, the first warning is not a problem, I think (but will double check), mCommonClipCount is negative when not initialised, but here is compared to the length of a list. I will see if the warning can be avoided somehow.

The second assertion is superfluous, I think it is a left over from an earlier version of the code. I'll make a patch to remove it asap.
(Assignee)

Comment 2

5 years ago
To confirm, the first warning is unavoidable because mCommonClipCount is -1 initially, but is safe because we are inside an 'if (mCommonClipCount >= 0)' block.
(Assignee)

Comment 3

5 years ago
Created attachment 623541 [details] [diff] [review]
remove the second warning

I assume this will be OK without a Try run?
Assignee: nobody → ncameron
Attachment #623541 - Flags: review?(dholbert)
(Reporter)

Comment 4

5 years ago
Comment on attachment 623541 [details] [diff] [review]
remove the second warning

Following the possible-callers of this method up, I found:
> 2399 FrameLayerBuilder::DrawThebesLayer(ThebesLayer* aLayer,
[...]
> 2404 {
[...]
> 2414   PRInt32 commonClipCount;
[...]
> 2537         currentClip.ApplyTo(aContext, presContext, commonClipCount);

(where ApplyTo is a wrapper for ApplyRoundedRectsTo, sort of)

So commonClipCount is a signed value that we're converting to unsigned, without ever checking that it's nonnegative, AFAICT.  So we could still potentially end up with a (wrapped) negative value at the place your assertion touches.

Assuming I'm reading this correctly -- rather than dropping the assertion entirely, could you bump it up a few stack-levels to just before that ApplyTo call?

Also, this patch only addresses one of the two warnings -- could you address the other one noted in comment 0 ("comparison between signed and unsigned integer expressions") as well?
(Reporter)

Comment 5

5 years ago
(In reply to Daniel Holbert [:dholbert] from comment #4)
> Also, this patch only addresses one of the two warnings -- could you address
> the other one noted in comment 0 ("comparison between signed and unsigned
> integer expressions") as well?

oh, sorry, I missed comment 2.

Could swap "mCommonClipCount" for "PRUint32(mCommonClipCount)" in that assertion, then? (perhaps with a comment noting that we're in a mCommonClipCount>=0 clause, if you like)
(Reporter)

Comment 6

5 years ago
*Could we swap
(Assignee)

Comment 7

5 years ago
The conversion from signed to unsigned is at line 1285, and is checked at line 1280. This is because there are two mCommonClipCounts in two different classes, one signed, one unsigned. The latter is used in DrawThebesLayer, there was a mistake in the signedness of commonClipCount that is corrected in the new patch.
(Assignee)

Comment 8

5 years ago
Created attachment 623596 [details] [diff] [review]
patch
Attachment #623541 - Attachment is obsolete: true
Attachment #623541 - Flags: review?(dholbert)
Attachment #623596 - Flags: review?(dholbert)
(Reporter)

Comment 9

5 years ago
Comment on attachment 623596 [details] [diff] [review]
patch

Ah, makes sense.

Side note: I noticed that the _unsigned_ version of mCommonClipCounts is initialized to -1, which seems odd:
> 533   class ThebesLayerItemsEntry : public nsPtrHashKey<ThebesLayer> {
> 534   public:
> 535     ThebesLayerItemsEntry(const ThebesLayer *key) :
> 536         nsPtrHashKey<ThebesLayer>(key), mContainerLayerFrame(nsnull),
> 537         mHasExplicitLastPaintOffset(false), mCommonClipCount(-1) {}
[...]
> 554     PRUint32 mCommonClipCount;

Perhaps that should be initialized to PR_UINT32_MAX instead of -1, to be clearer about its valid range?  (of course, they compute to the same value)

Either way, r=me
Attachment #623596 - Flags: review?(dholbert) → review+
(Assignee)

Comment 10

5 years ago
Created attachment 623806 [details] [diff] [review]
patch

Initialising ThebesLayerEntry::mCommonClipCount to 0, otherwise unchanged. Carrying r=dholbert
Attachment #623596 - Attachment is obsolete: true
Attachment #623806 - Flags: review+
(Reporter)

Comment 11

5 years ago
(Cool -- I'll take your word for it that 0 is a saner initial value than -1 was. :) )
(Assignee)

Updated

5 years ago
Keywords: checkin-needed
https://hg.mozilla.org/integration/mozilla-inbound/rev/78ab86f18887
Flags: in-testsuite-
Keywords: checkin-needed
Target Milestone: --- → mozilla15
https://hg.mozilla.org/mozilla-central/rev/78ab86f18887
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.