Bug 1323847: P3. Don't allocate data for empty buffer. r?gerald
MozReview-Commit-ID: I67RmFZpRDy
--- 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()) {