Closed Bug 1273409 Opened 8 years ago Closed 8 years ago

[Static Analysis][Dereference after null check] In function gfxUserFontSet::UserFontCache::Entry::ReportMemory

Categories

(Core :: Graphics, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla49
Tracking Status
firefox49 --- fixed

People

(Reporter: andi, Assigned: andi)

References

(Blocks 1 open bug)

Details

(Keywords: coverity, Whiteboard: CID 1361619 )

Attachments

(1 file)

The Static Analysis tool Coverity added that variable |mFontEntry| is dereferenced after it's null checked.

Null check:

>>        if (mFontEntry) { // this should always be present
>>            NS_ConvertUTF16toUTF8 familyName(mFontEntry->mFamilyName);
>>            path.AppendPrintf("family=%s", familyName.get());
>>        }

Dereference:

>>    return aCb->
>>        Callback(EmptyCString(), path,
>>                 nsIMemoryReporter::KIND_HEAP, nsIMemoryReporter::UNITS_BYTES,
>>                 mFontEntry->ComputedSizeOfExcludingThis(UserFontsMallocSizeOf),
>>                 NS_LITERAL_CSTRING("Memory used by @font-face resource."),
>>                 aClosure);

As it's imperative that the pointer should have a valid address i suggest eliminating the null check and adding an assert at the beginning of the function.
https://reviewboard.mozilla.org/r/53142/#review49946

::: gfx/thebes/gfxUserFontSet.cpp:1308
(Diff revision 1)
>  nsresult
>  gfxUserFontSet::UserFontCache::Entry::ReportMemory(nsIMemoryReporterCallback* aCb,
>                                                     nsISupports* aClosure,
>                                                     bool aAnonymize)
>  {
> +    MOZ_ASSERT(mFontEntry, "mFontEntry shouldn't be null");    

The assertion message here doesn't really add any value; just "MOZ_ASSERT(mFontEntry);" will do.

(And please get rid of the trailing space.)
Comment on attachment 8753245 [details]
MozReview Request: Bug 1273409 - add assert for mFontEntry. r?jrmuizel

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/53142/diff/1-2/
Attachment #8753245 - Flags: review?(jmuizelaar) → review+
Comment on attachment 8753245 [details]
MozReview Request: Bug 1273409 - add assert for mFontEntry. r?jrmuizel

https://reviewboard.mozilla.org/r/53142/#review50066

NotNull from bug 1272203 would probably help here.
https://hg.mozilla.org/mozilla-central/rev/f4dff50367ba
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla49
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: