Closed Bug 1297054 Opened 8 years ago Closed 8 years ago

[Static Analysis][Dereference before null check] in function CanvasRenderingContext2D::InitializeWithDrawTarget

Categories

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

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla51
Tracking Status
firefox51 --- fixed

People

(Reporter: andi, Assigned: andi)

References

(Blocks 1 open bug)

Details

(Keywords: coverity, Whiteboard: CID 1368323)

Attachments

(1 file)

The Static Analysis tool Coverity detected that |aTarget| is dereferenced before begin null checked:

>>  IntSize size = aTarget->GetSize();
>>  SetDimensions(size.width, size.height);
>>
>>  if (aTarget) {
>>    mTarget = aTarget;
>>    mBufferProvider = new PersistentBufferProviderBasic(aTarget);
>>  } else {
>>    EnsureErrorTarget();
>>    mTarget = sErrorTarget;
>>  }

There is no posibility that in this context a null pointer dereference can occur since the context where InitializeWithDrawTarget gets called null check aTarget:

>>        RefPtr<DrawTarget> canvasTarget =
>>          drawTarget->CreateSimilarDrawTarget(size, drawTarget->GetFormat());
>>        if (!canvasTarget) {
>>          continue;
>>        }
>>
>>        nsICanvasRenderingContextInternal* ctx = canvas->GetContextAtIndex(0);
>>        if (!ctx) {
>>          continue;
>>        }
>>
>>        // Initialize the context with the new DrawTarget.
>>        ctx->InitializeWithDrawTarget(nullptr, canvasTarget);
Comment on attachment 8783511 [details]
Bug 1297054 - remove null check in CanvasRenderingContext2D::InitializeWithDrawTarget.

https://reviewboard.mozilla.org/r/73304/#review71192

Can you change the signature of IntializeWithDrawTarget to use NotNull<gfx::DrawTarget*> aTarget?
Comment on attachment 8783511 [details]
Bug 1297054 - remove null check in CanvasRenderingContext2D::InitializeWithDrawTarget.

https://reviewboard.mozilla.org/r/73304/#review71194
Attachment #8783511 - Flags: review?(jmuizelaar) → review-
Comment on attachment 8783511 [details]
Bug 1297054 - remove null check in CanvasRenderingContext2D::InitializeWithDrawTarget.

https://reviewboard.mozilla.org/r/73304/#review71696
Attachment #8783511 - Flags: review?(jmuizelaar) → review+
Pushed by bpostelnicu@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/97158ba1395d
remove null check in CanvasRenderingContext2D::InitializeWithDrawTarget. r=jrmuizel
https://hg.mozilla.org/mozilla-central/rev/97158ba1395d
Status: NEW → RESOLVED
Closed: 8 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.

Attachment

General

Creator:
Created:
Updated:
Size: