Closed Bug 1240479 Opened 8 years ago Closed 8 years ago

[Static Analysis][Uninitialized scalar field] In function ElementPropertyTransition(...) from nsTransitionManager.h

Categories

(Core :: CSS Parsing and Computation, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla46
Tracking Status
firefox46 --- fixed

People

(Reporter: andi, Assigned: andi)

References

(Blocks 1 open bug)

Details

(Keywords: coverity, Whiteboard: CID 1348596 )

Attachments

(1 file, 1 obsolete file)

The Static Analysis tool Coverity added that variable mReversePortion it's not initialized in the constructor nor in any function that it calls.

Variable mReversePortion is used in function 

>>void
>>nsTransitionManager::ConsiderStartingTransition(
>>  nsCSSProperty aProperty,
>>  const StyleTransition& aTransition,
>>  dom::Element* aElement,
>>  AnimationCollection*& aElementTransitions,
>>  nsStyleContext* aOldStyleContext,
>>  nsStyleContext* aNewStyleContext,
>>  bool* aStartedAny,
>>  nsCSSPropertySet* aWhichStarted)

>>    // Compute the appropriate negative transition-delay such that right
>>    // now we'd end up at the current position.
>>    double valuePortion =
>>      oldPT->CurrentValuePortion() * oldPT->mReversePortion +
>>      (1.0 - oldPT->mReversePortion);

and it's attributed a value later on:

>>  RefPtr<ElementPropertyTransition> pt =
>>    new ElementPropertyTransition(aElement->OwnerDoc(), aElement,
>>                                  aNewStyleContext->GetPseudoType(), timing);
>>  pt->mStartForReversingTest = startForReversingTest;
>>  pt->mReversePortion = reversePortion;

The variable is used only if this will be valid:

>>  if (haveCurrentTransition &&
>>      aElementTransitions->mAnimations[currentIndex]->HasCurrentEffect() &&
>>      oldPT->mStartForReversingTest == endValue) 

Now i can't say for sure that the first time when functuion valls the above if will not be validated, and only the assignment will be called. I don't think that will hurt to initialize this variable in the constructor.
Comment on attachment 8708966 [details]
MozReview Request: Bug 1240479 - intialize mReversePortion in constructor. r?heycam

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/31199/diff/1-2/
Attachment #8708966 - Attachment description: MozReview Request: Bug 1240479 - intialize mReversePortion in constructor. r?bzbarsky@mit.edu → MozReview Request: Bug 1240479 - intialize mReversePortion in constructor. r?heycam
Attachment #8708966 - Flags: review?(cam)
Attachment #8708966 - Attachment is obsolete: true
Attachment #8708966 - Flags: review?(cam)
I don't think we're doing anything unsafe here, since the variable is initialized immediately after the object is constructed.  But maybe we want to initialize both mStartForReversingTest and mReversePortion based on values passed into the constructor instead.  That would save initializing those two variables with values that are immediately written over.  Brian?
Flags: needinfo?(bbirtles)
(In reply to Cameron McCormack (:heycam) from comment #4)
> I don't think we're doing anything unsafe here, since the variable is
> initialized immediately after the object is constructed.  But maybe we want
> to initialize both mStartForReversingTest and mReversePortion based on
> values passed into the constructor instead.  That would save initializing
> those two variables with values that are immediately written over.  Brian?

That's dbaron's code so he would know best but I think passing those values into the constructor sounds good.
Flags: needinfo?(bbirtles)
Comment on attachment 8708988 [details]
MozReview Request: Bug 1240479 - pass values for mReversePortion and mStartForReversingTestin through constructor. r?heycam

https://reviewboard.mozilla.org/r/31221/#review28107

Bogdan, could you change the constructor to take these two values instead?
Attachment #8708988 - Flags: review?(cam)
Comment on attachment 8708988 [details]
MozReview Request: Bug 1240479 - pass values for mReversePortion and mStartForReversingTestin through constructor. r?heycam

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/31221/diff/1-2/
Attachment #8708988 - Attachment description: MozReview Request: Bug 1240479 - intialize mReversePortion in constructor. r?heycam → MozReview Request: Bug 1240479 - pass values for mReversePortion and mStartForReversingTestin through constructor. r?heycam
Attachment #8708988 - Flags: review?(cam)
Comment on attachment 8708988 [details]
MozReview Request: Bug 1240479 - pass values for mReversePortion and mStartForReversingTestin through constructor. r?heycam

https://reviewboard.mozilla.org/r/31221/#review28113

Looks good, thanks!
Attachment #8708988 - Flags: review?(cam) → review+
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/ed0727ff1bef
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla46
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: