Bug 1363201 - fix the impl of WrVecU8, r=jrmuizel
authorAlexis Beingessner <a.beingessner@gmail.com>
Mon, 08 May 2017 17:24:39 -0400
changeset 359296 c509185bf7e5f29f4685b4f3d8d4467581b49cfa
parent 359295 f9fc89f8b6ff99102523607476d032626edb2ccd
child 359297 9d9046d172d6204b2e7b0c3453ba6c045dd4c9fd
push id31852
push userkwierso@gmail.com
push dateFri, 19 May 2017 21:47:27 +0000
treeherdermozilla-central@979f11deabd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1363201
milestone55.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 1363201 - fix the impl of WrVecU8, r=jrmuizel Two bugs: * We were failing to (re)initialize the length to 0, leading to segfaults on Rust processing "empty" lists. * We were setting the pointer of empty Vec's to null, which is technically UB in Rust because Vec tells Rust its pointer is non-null (this is why Option<Vec<T>> has the same size as Vec<T>). align_of::<T> is what it uses to as a non-null junk pointer, which in this case is 1. MozReview-Commit-ID: Gzy1NtKlSV7
gfx/webrender_bindings/WebRenderTypes.h
--- a/gfx/webrender_bindings/WebRenderTypes.h
+++ b/gfx/webrender_bindings/WebRenderTypes.h
@@ -419,40 +419,43 @@ static inline WrExternalImage NativeText
     aHandle, u0, v0, u1, v1,
     nullptr, 0
   };
 }
 
 struct VecU8 {
   WrVecU8 inner;
   VecU8() {
-    inner.data = nullptr;
-    inner.capacity = 0;
+    SetEmpty();
   }
   VecU8(VecU8&) = delete;
   VecU8(VecU8&& src) {
     inner = src.inner;
-    src.inner.data = nullptr;
-    src.inner.capacity = 0;
+    src.SetEmpty();
   }
 
   VecU8&
   operator=(VecU8&& src) {
     inner = src.inner;
-    src.inner.data = nullptr;
-    src.inner.capacity = 0;
+    src.SetEmpty();
     return *this;
   }
 
   WrVecU8
   Extract() {
     WrVecU8 ret = inner;
-    inner.data = nullptr;
+    SetEmpty();
+    return ret;
+  }
+
+  void
+  SetEmpty() {
+    inner.data = (uint8_t*)1;
     inner.capacity = 0;
-    return ret;
+    inner.length = 0;
   }
 
   ~VecU8() {
     if (inner.data) {
       wr_vec_u8_free(inner);
     }
   }
 };