Bug 1323847: P3. Don't allocate data for empty buffer. r=gerald
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 16 Dec 2016 16:20:06 +1100
changeset 450584 a617d810f29c22494e8d5947d6ae56e6a0411406
parent 450583 6fb5f5e18b909ebf91e65bcbe87870b4ecbf1f24
child 450585 b368a656365059332eecef77680972a6944f1784
push id38911
push userbmo:cku@mozilla.com
push dateSat, 17 Dec 2016 03:26:49 +0000
reviewersgerald
bugs1323847
milestone53.0a1
Bug 1323847: P3. Don't allocate data for empty buffer. r=gerald MozReview-Commit-ID: I67RmFZpRDy
dom/media/MediaData.h
--- a/dom/media/MediaData.h
+++ b/dom/media/MediaData.h
@@ -215,16 +215,20 @@ private:
 
   // Ensure that the backend buffer can hold aLength data. Will update mData.
   // Will enforce that the start of allocated data is always Alignment bytes
   // aligned and that it has sufficient end padding to allow for Alignment bytes
   // block read as required by some data decoders.
   // Returns false if memory couldn't be allocated.
   bool EnsureCapacity(size_t aLength)
   {
+    if (!aLength) {
+      // No need to allocate a buffer yet.
+      return true;
+    }
     const CheckedInt<size_t> sizeNeeded =
       CheckedInt<size_t>(aLength) * sizeof(Type) + AlignmentPaddingSize();
 
     if (!sizeNeeded.isValid() || sizeNeeded.value() >= INT32_MAX) {
       // overflow or over an acceptable size.
       return false;
     }
     if (mData && mCapacity >= sizeNeeded.value()) {