Closed Bug 1324245 Opened 3 years ago Closed 3 years ago

-Wnull-dereference warning in nsRefreshDriver.cpp

Categories

(Core :: Layout, defect)

defect
Not set

Tracking

()

RESOLVED FIXED
mozilla53
Tracking Status
firefox53 --- fixed

People

(Reporter: ehsan, Assigned: ehsan)

Details

Attachments

(1 file)

5:46.37 ../../../layout/base/nsRefreshDriver.cpp:1470:14: error: binding dereferenced null pointer to reference has undefined behavior [-Werror,-Wnull-dereference]
 5:46.37       return *static_cast<ObserverArray*>(nullptr);
 5:46.37              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 5:46.37 1 error generated.
Comment on attachment 8819612 [details] [diff] [review]
Avoid dereferencing nullptr in nsRefreshDriver::ArrayFor()

Review of attachment 8819612 [details] [diff] [review]:
-----------------------------------------------------------------

r=me, ideally with the comment clarified slightly (see below)

::: layout/base/nsRefreshDriver.cpp
@@ +1465,5 @@
>        return mObservers[1];
>      case Flush_Display:
>        return mObservers[2];
>      default:
> +      MOZ_CRASH("bad flush type");

"bad" is vague -- (out of bounds? invalid somehow?)  We could stand to be a bit more precise.

How about:
  MOZ_CRASH("We don't track refresh observers for this flush type");
or something along those lines?

(Note that the Style/Layout/Display restriction *is* mentioned in the header-comment for the APIs that trigger calls to this method:
https://dxr.mozilla.org/mozilla-central/rev/5745bab28ff5e85128c774b56b4cc27c2afe2e1b/layout/base/nsRefreshDriver.h#116
...so this requirement/restriction is already nicely documented.)
Attachment #8819612 - Flags: review?(dholbert) → review+
Pushed by eakhgari@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/ad2c9f799278
Avoid dereferencing nullptr in nsRefreshDriver::ArrayFor(); r=dholbert
https://hg.mozilla.org/mozilla-central/rev/ad2c9f799278
Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla53
You need to log in before you can comment on or make changes to this bug.