Closed Bug 1276140 Opened 8 years ago Closed 8 years ago

Avoid undefined behavior in frame properties table

Categories

(Core :: Layout, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla49
Tracking Status
firefox49 --- fixed

People

(Reporter: xidorn, Assigned: xidorn)

Details

Attachments

(1 file)

The current method that using union to reinterpret value is actually an undefined behavior per C++ spec, since it requires to access inactive union member.

Although many compilers implement a language extension to allow that, we may still want to avoid undefined behavior as much as possible.

Using memcpy is the safest way to do reinterpreting between unknown types, and most compilers are able to optimize it properly when possible.
Assignee: nobody → bugzilla
Attachment #8757140 - Flags: review?(nfroyd) → review+
Comment on attachment 8757140 [details]
MozReview Request: Bug 1276140 - Use memcpy rather than union to reinterpret in frame properties table. r?froydnj

https://reviewboard.mozilla.org/r/55682/#review52462

r=me with the changes below.

::: layout/base/FramePropertyTable.h:298
(Diff revision 1)
> +  template<typename T>
> +  struct ReinterpretHelper<T*>
> +  {
> +    static void* ToPointer(T* aValue)
> +    {
> +      return reinterpret_cast<void*>(aValue);

Casts to and from void pointers can be static_cast, here and below.
https://hg.mozilla.org/integration/mozilla-inbound/rev/bc8ea177c0d8303861f04c6009582acf40c692bb
Bug 1276140 - Use memcpy rather than union to reinterpret in frame properties table. r=froydnj
https://hg.mozilla.org/mozilla-central/rev/bc8ea177c0d8
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

Created:
Updated:
Size: