Bug 968520 - Add mozilla::fallible to Fallible{Auto,}TArray::SetLength calls. r=froydnj

This commit is contained in:
Birunthan Mohanathas 2015-05-18 13:50:35 -07:00
parent a0cd263bb6
commit 63dbcb194c
40 changed files with 64 additions and 60 deletions

View File

@ -376,7 +376,7 @@ WebGLElementArrayCacheTree<T>::Update(size_t firstByte, size_t lastByte)
// Step #0: If needed, resize our tree data storage.
if (requiredNumLeaves != NumLeaves()) {
// See class comment for why we the tree storage size is 2 * numLeaves.
if (!mTreeData.SetLength(2 * requiredNumLeaves)) {
if (!mTreeData.SetLength(2 * requiredNumLeaves, fallible)) {
mTreeData.SetLength(0);
return false;
}
@ -470,7 +470,7 @@ bool
WebGLElementArrayCache::BufferData(const void* ptr, size_t byteLength)
{
if (mBytes.Length() != byteLength) {
if (!mBytes.SetLength(byteLength)) {
if (!mBytes.SetLength(byteLength, fallible)) {
mBytes.SetLength(0);
return false;
}

View File

@ -152,7 +152,7 @@ ReadBuffer(JSStructuredCloneReader* aReader, CryptoBuffer& aBuffer)
}
if (length > 0) {
if (!aBuffer.SetLength(length)) {
if (!aBuffer.SetLength(length, fallible)) {
return false;
}
ret = JS_ReadBytes(aReader, aBuffer.Elements(), aBuffer.Length());

View File

@ -555,7 +555,7 @@ private:
// Initialize the output buffer (enough space for padding / a full tag)
uint32_t dataLen = mData.Length();
uint32_t maxLen = dataLen + 16;
if (!mResult.SetLength(maxLen)) {
if (!mResult.SetLength(maxLen, fallible)) {
return NS_ERROR_DOM_UNKNOWN_ERR;
}
uint32_t outLen = 0;
@ -679,7 +679,7 @@ private:
// Encrypt and return the wrapped key
// AES-KW encryption results in a wrapped key 64 bits longer
if (!mResult.SetLength(mData.Length() + 8)) {
if (!mResult.SetLength(mData.Length() + 8, fallible)) {
return NS_ERROR_DOM_OPERATION_ERR;
}
SECItem resultItem = {siBuffer, mResult.Elements(),
@ -811,7 +811,7 @@ private:
// Ciphertext is an integer mod the modulus, so it will be
// no longer than mStrength octets
if (!mResult.SetLength(mStrength)) {
if (!mResult.SetLength(mStrength, fallible)) {
return NS_ERROR_DOM_UNKNOWN_ERR;
}
@ -901,7 +901,7 @@ private:
virtual nsresult DoCrypto() override
{
// Initialize the output buffer
if (!mResult.SetLength(HASH_LENGTH_MAX)) {
if (!mResult.SetLength(HASH_LENGTH_MAX, fallible)) {
return NS_ERROR_DOM_UNKNOWN_ERR;
}
@ -1183,7 +1183,7 @@ private:
{
// Resize the result buffer
uint32_t hashLen = HASH_ResultLenByOidTag(mOidTag);
if (!mResult.SetLength(hashLen)) {
if (!mResult.SetLength(hashLen, fallible)) {
return NS_ERROR_DOM_UNKNOWN_ERR;
}
@ -2597,7 +2597,7 @@ private:
return NS_ERROR_DOM_DATA_ERR;
}
if (!mResult.SetLength(mLength)) {
if (!mResult.SetLength(mLength, fallible)) {
return NS_ERROR_DOM_UNKNOWN_ERR;
}
@ -2696,7 +2696,7 @@ private:
return NS_ERROR_DOM_DATA_ERR;
}
if (!mResult.SetLength(mLength)) {
if (!mResult.SetLength(mLength, fallible)) {
return NS_ERROR_DOM_UNKNOWN_ERR;
}

View File

@ -15771,7 +15771,7 @@ DatabaseOperationBase::GetStructuredCloneReadInfoFromBlob(
}
AutoFallibleTArray<uint8_t, 512> uncompressed;
if (NS_WARN_IF(!uncompressed.SetLength(uncompressedLength))) {
if (NS_WARN_IF(!uncompressed.SetLength(uncompressedLength, fallible))) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -21756,7 +21756,8 @@ ObjectStoreGetRequestOp::GetResponse(RequestResponse& aResponse)
if (!mResponse.IsEmpty()) {
FallibleTArray<SerializedStructuredCloneReadInfo> fallibleCloneInfos;
if (NS_WARN_IF(!fallibleCloneInfos.SetLength(mResponse.Length()))) {
if (NS_WARN_IF(!fallibleCloneInfos.SetLength(mResponse.Length(),
fallible))) {
aResponse = NS_ERROR_OUT_OF_MEMORY;
return;
}
@ -22304,7 +22305,8 @@ IndexGetRequestOp::GetResponse(RequestResponse& aResponse)
if (!mResponse.IsEmpty()) {
FallibleTArray<SerializedStructuredCloneReadInfo> fallibleCloneInfos;
if (NS_WARN_IF(!fallibleCloneInfos.SetLength(mResponse.Length()))) {
if (NS_WARN_IF(!fallibleCloneInfos.SetLength(mResponse.Length(),
fallible))) {
aResponse = NS_ERROR_OUT_OF_MEMORY;
return;
}

View File

@ -1178,7 +1178,8 @@ IDBObjectStore::AddOrPut(JSContext* aCx,
}
FallibleTArray<uint8_t> cloneData;
if (NS_WARN_IF(!cloneData.SetLength(cloneWriteInfo.mCloneBuffer.nbytes()))) {
if (NS_WARN_IF(!cloneData.SetLength(cloneWriteInfo.mCloneBuffer.nbytes(),
fallible))) {
aRv = NS_ERROR_OUT_OF_MEMORY;
return nullptr;
}

View File

@ -968,7 +968,7 @@ CreateBlobImpl(const nsTArray<BlobData>& aBlobDatas,
}
FallibleTArray<nsRefPtr<BlobImpl>> fallibleBlobImpls;
if (NS_WARN_IF(!fallibleBlobImpls.SetLength(aBlobDatas.Length()))) {
if (NS_WARN_IF(!fallibleBlobImpls.SetLength(aBlobDatas.Length(), fallible))) {
return nullptr;
}

View File

@ -625,7 +625,8 @@ MediaRawDataWriter::SetSize(size_t aSize)
// Pad our buffer. We ensure sufficient capacity above so this shouldn't fail.
MOZ_ALWAYS_TRUE(
mBuffer->SetLength(aSize + mTarget->mPadding + RAW_DATA_ALIGNMENT));
mBuffer->SetLength(aSize + mTarget->mPadding + RAW_DATA_ALIGNMENT,
fallible));
mTarget->mSize = mSize = aSize;
return true;
}

View File

@ -35,7 +35,7 @@ MP4Demuxer::Init()
return InitPromise::CreateAndReject(DemuxerFailureReason::WAITING_FOR_DATA, __func__);
}
if (!mInitData->SetLength(br.Length())) {
if (!mInitData->SetLength(br.Length(), fallible)) {
// OOM
return InitPromise::CreateAndReject(DemuxerFailureReason::DEMUXER_ERROR, __func__);
}

View File

@ -175,7 +175,7 @@ public:
if (initSegment || !HasCompleteInitData()) {
if (mParser.mInitEndOffset > 0) {
MOZ_ASSERT(mParser.mInitEndOffset <= mResource->GetLength());
if (!mInitData->SetLength(mParser.mInitEndOffset)) {
if (!mInitData->SetLength(mParser.mInitEndOffset, fallible)) {
// Super unlikely OOM
return false;
}
@ -306,7 +306,7 @@ public:
const MediaByteRange& range = mParser->mInitRange;
uint32_t length = range.mEnd - range.mStart;
if (length) {
if (!mInitData->SetLength(length)) {
if (!mInitData->SetLength(length, fallible)) {
// Super unlikely OOM
return false;
}

View File

@ -62,7 +62,7 @@ public:
// These allocations might fail if content provides a huge number of
// channels or size, but it's OK since we'll deal with the failure
// gracefully.
if (mInputChannels.SetLength(mNumberOfChannels)) {
if (mInputChannels.SetLength(mNumberOfChannels, fallible)) {
for (uint32_t i = 0; i < mNumberOfChannels; ++i) {
mInputChannels[i] = new (fallible) float[mLength];
if (!mInputChannels[i]) {

View File

@ -196,7 +196,7 @@ DelayBuffer::EnsureBuffer()
// block size, so that no block of writes will need to wrap.
const int chunkCount = (mMaxDelayTicks + 2 * WEBAUDIO_BLOCK_SIZE - 1) >>
WEBAUDIO_BLOCK_SIZE_BITS;
if (!mChunks.SetLength(chunkCount)) {
if (!mChunks.SetLength(chunkCount, fallible)) {
return false;
}

View File

@ -352,7 +352,7 @@ MediaDecodeTask::FinishDecode()
// write fewer bytes than mResampledFrames to the output buffer, in which
// case mWriteIndex will tell us how many valid samples we have.
bool memoryAllocationSuccess = true;
if (!mDecodeJob.mChannelBuffers.SetLength(channelCount)) {
if (!mDecodeJob.mChannelBuffers.SetLength(channelCount, fallible)) {
memoryAllocationSuccess = false;
} else {
for (uint32_t i = 0; i < channelCount; ++i) {

View File

@ -356,7 +356,7 @@ MobileMessageManager::Delete(const Sequence<OwningLongOrMozSmsMessageOrMozMmsMes
{
const uint32_t size = aParams.Length();
FallibleTArray<int32_t> idArray;
if (!idArray.SetLength(size)) {
if (!idArray.SetLength(size, fallible)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
}

View File

@ -778,7 +778,7 @@ PluginScriptableObjectChild::AnswerInvoke(const PluginIdentifier& aId,
AutoFallibleTArray<NPVariant, 10> convertedArgs;
uint32_t argCount = aArgs.Length();
if (!convertedArgs.SetLength(argCount)) {
if (!convertedArgs.SetLength(argCount, mozilla::fallible)) {
*aResult = void_t();
*aSuccess = false;
return true;
@ -848,7 +848,7 @@ PluginScriptableObjectChild::AnswerInvokeDefault(InfallibleTArray<Variant>&& aAr
AutoFallibleTArray<NPVariant, 10> convertedArgs;
uint32_t argCount = aArgs.Length();
if (!convertedArgs.SetLength(argCount)) {
if (!convertedArgs.SetLength(argCount, mozilla::fallible)) {
*aResult = void_t();
*aSuccess = false;
return true;
@ -1099,7 +1099,7 @@ PluginScriptableObjectChild::AnswerConstruct(InfallibleTArray<Variant>&& aArgs,
AutoFallibleTArray<NPVariant, 10> convertedArgs;
uint32_t argCount = aArgs.Length();
if (!convertedArgs.SetLength(argCount)) {
if (!convertedArgs.SetLength(argCount, mozilla::fallible)) {
*aResult = void_t();
*aSuccess = false;
return true;

View File

@ -824,7 +824,7 @@ PluginScriptableObjectParent::AnswerInvoke(const PluginIdentifier& aId,
AutoFallibleTArray<NPVariant, 10> convertedArgs;
uint32_t argCount = aArgs.Length();
if (!convertedArgs.SetLength(argCount)) {
if (!convertedArgs.SetLength(argCount, fallible)) {
*aResult = void_t();
*aSuccess = false;
return true;
@ -907,7 +907,7 @@ PluginScriptableObjectParent::AnswerInvokeDefault(InfallibleTArray<Variant>&& aA
AutoFallibleTArray<NPVariant, 10> convertedArgs;
uint32_t argCount = aArgs.Length();
if (!convertedArgs.SetLength(argCount)) {
if (!convertedArgs.SetLength(argCount, fallible)) {
*aResult = void_t();
*aSuccess = false;
return true;
@ -1227,7 +1227,7 @@ PluginScriptableObjectParent::AnswerConstruct(InfallibleTArray<Variant>&& aArgs,
AutoFallibleTArray<NPVariant, 10> convertedArgs;
uint32_t argCount = aArgs.Length();
if (!convertedArgs.SetLength(argCount)) {
if (!convertedArgs.SetLength(argCount, fallible)) {
*aResult = void_t();
*aSuccess = false;
return true;

View File

@ -131,7 +131,7 @@ DOMSVGLengthList::InternalListLengthWillChange(uint32_t aNewLength)
}
}
if (!mItems.SetLength(aNewLength)) {
if (!mItems.SetLength(aNewLength, fallible)) {
// We silently ignore SetLength OOM failure since being out of sync is safe
// so long as we have *fewer* items than our internal list.
mItems.Clear();

View File

@ -132,7 +132,7 @@ DOMSVGNumberList::InternalListLengthWillChange(uint32_t aNewLength)
}
}
if (!mItems.SetLength(aNewLength)) {
if (!mItems.SetLength(aNewLength, fallible)) {
// We silently ignore SetLength OOM failure since being out of sync is safe
// so long as we have *fewer* items than our internal list.
mItems.Clear();

View File

@ -166,7 +166,7 @@ DOMSVGPointList::InternalListWillChangeTo(const SVGPointList& aNewValue)
}
}
if (!mItems.SetLength(newLength)) {
if (!mItems.SetLength(newLength, fallible)) {
// We silently ignore SetLength OOM failure since being out of sync is safe
// so long as we have *fewer* items than our internal list.
mItems.Clear();

View File

@ -132,7 +132,7 @@ DOMSVGTransformList::InternalListLengthWillChange(uint32_t aNewLength)
}
}
if (!mItems.SetLength(aNewLength)) {
if (!mItems.SetLength(aNewLength, fallible)) {
// We silently ignore SetLength OOM failure since being out of sync is safe
// so long as we have *fewer* items than our internal list.
mItems.Clear();

View File

@ -90,7 +90,7 @@ protected:
* increased, in which case the list will be left unmodified.
*/
bool SetLength(uint32_t aNumberOfItems) {
return mLengths.SetLength(aNumberOfItems);
return mLengths.SetLength(aNumberOfItems, fallible);
}
private:

View File

@ -91,7 +91,7 @@ protected:
* increased, in which case the list will be left unmodified.
*/
bool SetLength(uint32_t aNumberOfItems) {
return mNumbers.SetLength(aNumberOfItems);
return mNumbers.SetLength(aNumberOfItems, fallible);
}
private:

View File

@ -81,7 +81,7 @@ SVGPathData::AppendSeg(uint32_t aType, ...)
{
uint32_t oldLength = mData.Length();
uint32_t newLength = oldLength + 1 + SVGPathSegUtils::ArgCountForType(aType);
if (!mData.SetLength(newLength)) {
if (!mData.SetLength(newLength, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -202,7 +202,7 @@ protected:
* increased, in which case the list will be left unmodified.
*/
bool SetLength(uint32_t aLength) {
return mData.SetLength(aLength);
return mData.SetLength(aLength, fallible);
}
nsresult SetValueFromString(const nsAString& aValue);

View File

@ -99,7 +99,7 @@ protected:
* increased, in which case the list will be left unmodified.
*/
bool SetLength(uint32_t aNumberOfItems) {
return mItems.SetLength(aNumberOfItems);
return mItems.SetLength(aNumberOfItems, fallible);
}
private:

View File

@ -92,7 +92,7 @@ protected:
* increased, in which case the list will be left unmodified.
*/
bool SetLength(uint32_t aStringOfItems) {
return mStrings.SetLength(aStringOfItems);
return mStrings.SetLength(aStringOfItems, fallible);
}
private:

View File

@ -94,7 +94,7 @@ protected:
* increased, in which case the list will be left unmodified.
*/
bool SetLength(uint32_t aNumberOfItems) {
return mItems.SetLength(aNumberOfItems);
return mItems.SetLength(aNumberOfItems, fallible);
}
private:

View File

@ -461,7 +461,7 @@ gfxContext::CurrentDash(FallibleTArray<gfxFloat>& dashes, gfxFloat* offset) cons
const AzureState &state = CurrentState();
int count = state.strokeOptions.mDashLength;
if (count <= 0 || !dashes.SetLength(count)) {
if (count <= 0 || !dashes.SetLength(count, fallible)) {
return false;
}

View File

@ -315,7 +315,7 @@ gfxCoreTextShaper::SetGlyphsFromRun(gfxShapedText *aShapedText,
static const int32_t NO_GLYPH = -1;
AutoFallibleTArray<int32_t,SMALL_GLYPH_RUN> charToGlyphArray;
if (!charToGlyphArray.SetLength(stringRange.length)) {
if (!charToGlyphArray.SetLength(stringRange.length, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
int32_t *charToGlyph = charToGlyphArray.Elements();

View File

@ -213,10 +213,10 @@ gfxGraphiteShaper::SetGlyphsFromSegment(gfxContext *aContext,
AutoFallibleTArray<float,SMALL_GLYPH_RUN> xLocs;
AutoFallibleTArray<float,SMALL_GLYPH_RUN> yLocs;
if (!clusters.SetLength(aLength) ||
!gids.SetLength(glyphCount) ||
!xLocs.SetLength(glyphCount) ||
!yLocs.SetLength(glyphCount))
if (!clusters.SetLength(aLength, fallible) ||
!gids.SetLength(glyphCount, fallible) ||
!xLocs.SetLength(glyphCount, fallible) ||
!yLocs.SetLength(glyphCount, fallible))
{
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -1534,7 +1534,7 @@ gfxHarfBuzzShaper::SetGlyphsFromRun(gfxContext *aContext,
uint32_t wordLength = aLength;
static const int32_t NO_GLYPH = -1;
AutoFallibleTArray<int32_t,SMALL_GLYPH_RUN> charToGlyphArray;
if (!charToGlyphArray.SetLength(wordLength)) {
if (!charToGlyphArray.SetLength(wordLength, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -370,7 +370,7 @@ CopyWOFFMetadata(const uint8_t* aFontData,
if (metaOffset >= aLength || metaCompLen > aLength - metaOffset) {
return;
}
if (!aMetadata->SetLength(woff->metaCompLen)) {
if (!aMetadata->SetLength(woff->metaCompLen, fallible)) {
return;
}
memcpy(aMetadata->Elements(), aFontData + metaOffset, metaCompLen);

View File

@ -46,7 +46,7 @@ nsresult
nsHyphenator::Hyphenate(const nsAString& aString,
FallibleTArray<bool>& aHyphens)
{
if (!aHyphens.SetLength(aString.Length())) {
if (!aHyphens.SetLength(aString.Length(), mozilla::fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
memset(aHyphens.Elements(), false, aHyphens.Length() * sizeof(bool));

View File

@ -343,7 +343,7 @@ def _callCxxArrayLength(arr):
def _callCxxCheckedArraySetLength(arr, lenexpr, sel='.'):
ifbad = StmtIf(ExprNot(ExprCall(ExprSelect(arr, sel, 'SetLength'),
args=[ lenexpr ])))
args=[ lenexpr, ExprVar('mozilla::fallible') ])))
ifbad.addifstmt(_fatalError('Error setting the array length'))
ifbad.addifstmt(StmtReturn.FALSE)
return ifbad

View File

@ -1454,7 +1454,7 @@ GetStrokeDashData(nsIFrame* aFrame,
} else {
uint32_t count = style->mStrokeDasharrayLength;
if (!count || !aDashes.SetLength(count)) {
if (!count || !aDashes.SetLength(count, fallible)) {
return false;
}

View File

@ -2205,7 +2205,7 @@ status_t MPEG4Extractor::parseMetaData(off64_t offset, size_t size) {
}
FallibleTArray<uint8_t> bufferBackend;
if (!bufferBackend.SetLength(size + 1)) {
if (!bufferBackend.SetLength(size + 1, mozilla::fallible)) {
// OOM ignore metadata.
return OK;
}
@ -3352,7 +3352,7 @@ bool MPEG4Source::ensureSrcBufferAllocated(int32_t aSize) {
if (mSrcBackend.Length() >= aSize) {
return true;
}
if (!mSrcBackend.SetLength(aSize)) {
if (!mSrcBackend.SetLength(aSize, mozilla::fallible)) {
ALOGE("Error insufficient memory, requested %u bytes (had:%u)",
aSize, mSrcBackend.Length());
return false;

View File

@ -204,7 +204,7 @@ bool MediaBuffer::ensuresize(size_t length) {
if (!mOwnsData || refcount()) {
return false;
}
if (!mBufferBackend.SetLength(length)) {
if (!mBufferBackend.SetLength(length, mozilla::fallible)) {
return false;
}
mData = mBufferBackend.Elements();

View File

@ -81,7 +81,7 @@ ChunkSet::Remove(const ChunkSet& aOther)
}
}
if (!mChunks.SetLength(addIter - mChunks.Elements())) {
if (!mChunks.SetLength(addIter - mChunks.Elements(), fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -289,7 +289,7 @@ template<class T>
nsresult
ReadTArray(nsIInputStream* aStream, FallibleTArray<T>* aArray, uint32_t aNumElements)
{
if (!aArray->SetLength(aNumElements))
if (!aArray->SetLength(aNumElements, fallible))
return NS_ERROR_OUT_OF_MEMORY;
void *buffer = aArray->Elements();

View File

@ -579,7 +579,7 @@ nsresult DeflateWriteTArray(nsIOutputStream* aStream, nsTArray<T>& aIn)
uLongf insize = aIn.Length() * sizeof(T);
uLongf outsize = compressBound(insize);
FallibleTArray<char> outBuff;
if (!outBuff.SetLength(outsize)) {
if (!outBuff.SetLength(outsize, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -622,7 +622,7 @@ nsresult InflateReadTArray(nsIInputStream* aStream, FallibleTArray<T>* aOut,
NS_ASSERTION(read == sizeof(inLen), "Error reading inflate length");
FallibleTArray<char> inBuff;
if (!inBuff.SetLength(inLen)) {
if (!inBuff.SetLength(inLen, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -631,7 +631,7 @@ nsresult InflateReadTArray(nsIInputStream* aStream, FallibleTArray<T>* aOut,
uLongf insize = inLen;
uLongf outsize = aExpectedSize * sizeof(T);
if (!aOut->SetLength(aExpectedSize)) {
if (!aOut->SetLength(aExpectedSize, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -133,7 +133,7 @@ nsUrlClassifierPrefixSet::MakePrefixSet(const uint32_t* aPrefixes, uint32_t aLen
nsresult
nsUrlClassifierPrefixSet::GetPrefixesNative(FallibleTArray<uint32_t>& outArray)
{
if (!outArray.SetLength(mTotalPrefixes)) {
if (!outArray.SetLength(mTotalPrefixes, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}