Closed Bug 1297048 Opened 4 years ago Closed 4 years ago

[Static Analysis][Dereference before null check] In function DragEvent::InitDragEvent

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set

Tracking

()

RESOLVED FIXED
mozilla51
Tracking Status
firefox51 --- fixed

People

(Reporter: andi, Assigned: andi)

References

(Blocks 1 open bug)

Details

(Keywords: coverity, Whiteboard: CID 1368322)

Attachments

(1 file)

The Static Analysis tool Coverity detected that |mEvent| is dereferenced before being null checked.

>>  MouseEvent::InitMouseEvent(aType, aCanBubble, aCancelable,
>>                             aView, aDetail, aScreenX, aScreenY,
>>                             aClientX, aClientY, aCtrlKey, aAltKey,
>>                             aShiftKey, aMetaKey, aButton, aRelatedTarget);
>>  if (mEventIsInternal && mEvent) {
>>    mEvent->AsDragEvent()->mDataTransfer = aDataTransfer;
>>  }

The dereference takes place in InitMouseEvent:

>>  UIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, aDetail);
>>
>>  switch(mEvent->mClass) {
>>    case eMouseEventClass:

In this case this is a false-positive since |mEvent| gets allocated in function Event::ConstructorInit. The call for ConstructorInit is done through the constructor of Event, that finally gets called through contructors of: 
DragEvent->MouseEvent->UIEvent->Event 

What i would like is to remove the null check to eliminate this fp.
Comment on attachment 8783495 [details]
Bug 1297048 - remove useless null check in DragEvent::InitDragEvent.

https://reviewboard.mozilla.org/r/73290/#review71288

Anyway, mEvent is never nullptr at least in normal path since it's allocated by each constructor when WidgetEvent argument is nullptr.
Attachment #8783495 - Flags: review?(masayuki) → review+
Pushed by bpostelnicu@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/750ba0b42ce3
remove useless null check in DragEvent::InitDragEvent. r=masayuki
https://hg.mozilla.org/mozilla-central/rev/750ba0b42ce3
Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla51
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.