Bug 1520418 - Ensure the empty array header has enough alignment to avoid creating unaligned pointers. r=froydnj
authorxftroxgpx <xftroxgpx@protonmail.com>
Wed, 16 Jan 2019 15:40:42 +0100
changeset 511303 319fa2b1377fb177b09eff33ae2c222acd20dc46
parent 511302 66b68c6b62216a62eccb99b050ee544aa3157f25
child 511304 4d5f1517ef85015541fe967b643d7539e9cc42d6
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1520418, 22613
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1520418 - Ensure the empty array header has enough alignment to avoid creating unaligned pointers. r=froydnj See https://github.com/servo/servo/issues/22613.
xpcom/ds/nsTArray.cpp
--- a/xpcom/ds/nsTArray.cpp
+++ b/xpcom/ds/nsTArray.cpp
@@ -6,17 +6,20 @@
 
 #include <string.h>
 #include "nsTArray.h"
 #include "nsXPCOM.h"
 #include "nsDebug.h"
 #include "mozilla/CheckedInt.h"
 #include "mozilla/IntegerPrintfMacros.h"
 
-nsTArrayHeader sEmptyTArrayHeader = {0, 0, 0};
+// Ensure this is sufficiently aligned so that Elements() and co don't create
+// unaligned pointers, or slices with unaligned pointers for empty arrays, see
+// https://github.com/servo/servo/issues/22613.
+alignas(8) nsTArrayHeader sEmptyTArrayHeader = {0, 0, 0};
 
 bool IsTwiceTheRequiredBytesRepresentableAsUint32(size_t aCapacity,
                                                   size_t aElemSize) {
   using mozilla::CheckedUint32;
   return ((CheckedUint32(aCapacity) * aElemSize) * 2).isValid();
 }
 
 MOZ_NORETURN MOZ_COLD void InvalidArrayIndex_CRASH(size_t aIndex,