diff --git a/dom/base/nsContentList.cpp b/dom/base/nsContentList.cpp index 9d9dc76509bc..7a4a0f2d3ea0 100644 --- a/dom/base/nsContentList.cpp +++ b/dom/base/nsContentList.cpp @@ -224,7 +224,7 @@ NS_GetContentList(nsINode* aRootNode, // First we look in our hashtable. Then we create a content list if needed if (gContentListHashTable.IsInitialized()) { entry = static_cast - (PL_DHashTableAdd(&gContentListHashTable, &hashKey)); + (PL_DHashTableAdd(&gContentListHashTable, &hashKey, fallible)); if (entry) list = entry->mContentList; } @@ -332,8 +332,7 @@ GetFuncStringContentList(nsINode* aRootNode, nsFuncStringCacheKey hashKey(aRootNode, aFunc, aString); entry = static_cast - (PL_DHashTableAdd(&gFuncStringContentListHashTable, - &hashKey)); + (PL_DHashTableAdd(&gFuncStringContentListHashTable, &hashKey, fallible)); if (entry) { list = entry->mContentList; #ifdef DEBUG diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index fad754ed459d..19227a91d680 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -3963,7 +3963,7 @@ nsContentUtils::GetListenerManagerForNode(nsINode *aNode) EventListenerManagerMapEntry *entry = static_cast - (PL_DHashTableAdd(&sEventListenerManagersHash, aNode)); + (PL_DHashTableAdd(&sEventListenerManagersHash, aNode, fallible)); if (!entry) { return nullptr; diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index d796bb0ebe1e..ca2bf579c26a 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -4007,9 +4007,8 @@ nsDocument::SetSubDocumentFor(Element* aElement, nsIDocument* aSubDoc) } // Add a mapping to the hash table - SubDocMapEntry *entry = - static_cast - (PL_DHashTableAdd(mSubDocuments, aElement)); + SubDocMapEntry *entry = static_cast + (PL_DHashTableAdd(mSubDocuments, aElement, fallible)); if (!entry) { return NS_ERROR_OUT_OF_MEMORY; diff --git a/dom/base/nsPropertyTable.cpp b/dom/base/nsPropertyTable.cpp index 0dec88123e81..13e42240b462 100644 --- a/dom/base/nsPropertyTable.cpp +++ b/dom/base/nsPropertyTable.cpp @@ -230,7 +230,7 @@ nsPropertyTable::SetPropertyInternal(nsPropertyOwner aObject, // value is destroyed nsresult result = NS_OK; PropertyListMapEntry *entry = static_cast - (PL_DHashTableAdd(&propertyList->mObjectValueMap, aObject)); + (PL_DHashTableAdd(&propertyList->mObjectValueMap, aObject, fallible)); if (!entry) return NS_ERROR_OUT_OF_MEMORY; // A nullptr entry->key is the sign that the entry has just been allocated diff --git a/dom/base/nsScriptNameSpaceManager.cpp b/dom/base/nsScriptNameSpaceManager.cpp index f71d24858cd5..021bd02f36ed 100644 --- a/dom/base/nsScriptNameSpaceManager.cpp +++ b/dom/base/nsScriptNameSpaceManager.cpp @@ -140,9 +140,8 @@ nsGlobalNameStruct * nsScriptNameSpaceManager::AddToHash(PLDHashTable *aTable, const nsAString *aKey, const char16_t **aClassName) { - GlobalNameMapEntry *entry = - static_cast - (PL_DHashTableAdd(aTable, aKey)); + GlobalNameMapEntry *entry = static_cast + (PL_DHashTableAdd(aTable, aKey, fallible)); if (!entry) { return nullptr; diff --git a/dom/plugins/base/nsJSNPRuntime.cpp b/dom/plugins/base/nsJSNPRuntime.cpp index 562fde7fec76..874fe228ddce 100644 --- a/dom/plugins/base/nsJSNPRuntime.cpp +++ b/dom/plugins/base/nsJSNPRuntime.cpp @@ -1872,7 +1872,7 @@ nsNPObjWrapper::GetNewOrUsed(NPP npp, JSContext *cx, NPObject *npobj) } NPObjWrapperHashEntry *entry = static_cast - (PL_DHashTableAdd(&sNPObjWrappers, npobj)); + (PL_DHashTableAdd(&sNPObjWrappers, npobj, fallible)); if (!entry) { // Out of memory @@ -2035,7 +2035,7 @@ LookupNPP(NPObject *npobj) } NPObjWrapperHashEntry *entry = static_cast - (PL_DHashTableAdd(&sNPObjWrappers, npobj)); + (PL_DHashTableAdd(&sNPObjWrappers, npobj, fallible)); if (!entry) { return nullptr; diff --git a/dom/xul/XULDocument.cpp b/dom/xul/XULDocument.cpp index 1dbc439da409..c948d8f6e1f1 100644 --- a/dom/xul/XULDocument.cpp +++ b/dom/xul/XULDocument.cpp @@ -781,9 +781,8 @@ XULDocument::AddBroadcastListenerFor(Element& aBroadcaster, Element& aListener, (PL_DHashTableSearch(mBroadcasterMap, &aBroadcaster)); if (!entry) { - entry = - static_cast - (PL_DHashTableAdd(mBroadcasterMap, &aBroadcaster)); + entry = static_cast + (PL_DHashTableAdd(mBroadcasterMap, &aBroadcaster, fallible)); if (! entry) { aRv.Throw(NS_ERROR_OUT_OF_MEMORY); diff --git a/dom/xul/templates/nsContentSupportMap.h b/dom/xul/templates/nsContentSupportMap.h index 253dbbe989b5..f61a09027a7e 100644 --- a/dom/xul/templates/nsContentSupportMap.h +++ b/dom/xul/templates/nsContentSupportMap.h @@ -28,7 +28,8 @@ public: if (!mMap.IsInitialized()) return NS_ERROR_NOT_INITIALIZED; - PLDHashEntryHdr* hdr = PL_DHashTableAdd(&mMap, aElement); + PLDHashEntryHdr* hdr = + PL_DHashTableAdd(&mMap, aElement, mozilla::fallible); if (!hdr) return NS_ERROR_OUT_OF_MEMORY; diff --git a/dom/xul/templates/nsTemplateMap.h b/dom/xul/templates/nsTemplateMap.h index e87faa41086c..71203f559746 100644 --- a/dom/xul/templates/nsTemplateMap.h +++ b/dom/xul/templates/nsTemplateMap.h @@ -37,7 +37,8 @@ public: NS_ASSERTION(!PL_DHashTableSearch(&mTable, aContent), "aContent already in map"); - Entry* entry = static_cast(PL_DHashTableAdd(&mTable, aContent)); + Entry* entry = static_cast + (PL_DHashTableAdd(&mTable, aContent, fallible)); if (entry) { entry->mContent = aContent; diff --git a/embedding/components/commandhandler/nsCommandParams.cpp b/embedding/components/commandhandler/nsCommandParams.cpp index 2bfc80e670c0..cc36ee2c8f0e 100644 --- a/embedding/components/commandhandler/nsCommandParams.cpp +++ b/embedding/components/commandhandler/nsCommandParams.cpp @@ -230,7 +230,8 @@ nsCommandParams::GetOrMakeEntry(const char* aName, uint8_t entryType) return foundEntry; } - foundEntry = (HashEntry *)PL_DHashTableAdd(&mValuesHash, (void *)aName); + foundEntry = static_cast + (PL_DHashTableAdd(&mValuesHash, (void *)aName, fallible)); if (!foundEntry) { return nullptr; } diff --git a/gfx/thebes/gfxFT2FontList.cpp b/gfx/thebes/gfxFT2FontList.cpp index 48bcfc332ebf..671813b3d6d6 100644 --- a/gfx/thebes/gfxFT2FontList.cpp +++ b/gfx/thebes/gfxFT2FontList.cpp @@ -688,9 +688,8 @@ public: } uint32_t filesize = strtoul(beginning, nullptr, 10); - FNCMapEntry* mapEntry = - static_cast - (PL_DHashTableAdd(&mMap, filename.get())); + FNCMapEntry* mapEntry = static_cast + (PL_DHashTableAdd(&mMap, filename.get(), fallible)); if (mapEntry) { mapEntry->mFilename.Assign(filename); mapEntry->mTimestamp = timestamp; @@ -737,9 +736,8 @@ public: if (!mMap.IsInitialized()) { return; } - FNCMapEntry* entry = - static_cast - (PL_DHashTableAdd(&mMap, aFileName.get())); + FNCMapEntry* entry = static_cast + (PL_DHashTableAdd(&mMap, aFileName.get(), fallible)); if (entry) { entry->mFilename.Assign(aFileName); entry->mTimestamp = aTimestamp; diff --git a/js/xpconnect/src/XPCMaps.cpp b/js/xpconnect/src/XPCMaps.cpp index c70846f570bb..e406878e61c8 100644 --- a/js/xpconnect/src/XPCMaps.cpp +++ b/js/xpconnect/src/XPCMaps.cpp @@ -626,7 +626,8 @@ XPCNativeScriptableSharedMap::GetNewOrUsed(uint32_t flags, NS_PRECONDITION(si,"bad param"); XPCNativeScriptableShared key(flags, name); - Entry* entry = (Entry*) PL_DHashTableAdd(mTable, &key); + Entry* entry = static_cast + (PL_DHashTableAdd(mTable, &key, fallible)); if (!entry) return false; diff --git a/js/xpconnect/src/XPCMaps.h b/js/xpconnect/src/XPCMaps.h index ffc310112a04..81e6f49656fc 100644 --- a/js/xpconnect/src/XPCMaps.h +++ b/js/xpconnect/src/XPCMaps.h @@ -120,7 +120,8 @@ public: NS_PRECONDITION(wrapper,"bad param"); nsISupports* obj = wrapper->GetIdentityObject(); MOZ_ASSERT(!Find(obj), "wrapper already in new scope!"); - Entry* entry = (Entry*) PL_DHashTableAdd(mTable, obj); + Entry* entry = static_cast + (PL_DHashTableAdd(mTable, obj, mozilla::fallible)); if (!entry) return nullptr; if (entry->key) @@ -185,7 +186,8 @@ public: { NS_PRECONDITION(clazz,"bad param"); const nsIID* iid = &clazz->GetIID(); - Entry* entry = (Entry*) PL_DHashTableAdd(mTable, iid); + Entry* entry = static_cast + (PL_DHashTableAdd(mTable, iid, mozilla::fallible)); if (!entry) return nullptr; if (entry->key) @@ -238,7 +240,8 @@ public: { NS_PRECONDITION(iface,"bad param"); const nsIID* iid = iface->GetIID(); - Entry* entry = (Entry*) PL_DHashTableAdd(mTable, iid); + Entry* entry = static_cast + (PL_DHashTableAdd(mTable, iid, mozilla::fallible)); if (!entry) return nullptr; if (entry->key) @@ -293,7 +296,8 @@ public: inline XPCNativeSet* Add(nsIClassInfo* info, XPCNativeSet* set) { NS_PRECONDITION(info,"bad param"); - Entry* entry = (Entry*) PL_DHashTableAdd(mTable, info); + Entry* entry = static_cast + (PL_DHashTableAdd(mTable, info, mozilla::fallible)); if (!entry) return nullptr; if (entry->key) @@ -349,7 +353,8 @@ public: inline XPCWrappedNativeProto* Add(nsIClassInfo* info, XPCWrappedNativeProto* proto) { NS_PRECONDITION(info,"bad param"); - Entry* entry = (Entry*) PL_DHashTableAdd(mTable, info); + Entry* entry = static_cast + (PL_DHashTableAdd(mTable, info, mozilla::fallible)); if (!entry) return nullptr; if (entry->key) @@ -411,7 +416,8 @@ public: { NS_PRECONDITION(key,"bad param"); NS_PRECONDITION(set,"bad param"); - Entry* entry = (Entry*) PL_DHashTableAdd(mTable, key); + Entry* entry = static_cast + (PL_DHashTableAdd(mTable, key, mozilla::fallible)); if (!entry) return nullptr; if (entry->key_value) @@ -483,8 +489,8 @@ public: inline nsIXPCFunctionThisTranslator* Add(REFNSIID iid, nsIXPCFunctionThisTranslator* obj) { - - Entry* entry = (Entry*) PL_DHashTableAdd(mTable, &iid); + Entry* entry = static_cast + (PL_DHashTableAdd(mTable, &iid, mozilla::fallible)); if (!entry) return nullptr; entry->value = obj; @@ -555,8 +561,8 @@ public: inline XPCWrappedNativeProto* Add(XPCWrappedNativeProto* proto) { NS_PRECONDITION(proto,"bad param"); - PLDHashEntryStub* entry = (PLDHashEntryStub*) - PL_DHashTableAdd(mTable, proto); + PLDHashEntryStub* entry = static_cast + (PL_DHashTableAdd(mTable, proto, mozilla::fallible)); if (!entry) return nullptr; if (entry->key) diff --git a/layout/base/nsFrameManager.cpp b/layout/base/nsFrameManager.cpp index d34d0e581655..7b43cffd5555 100644 --- a/layout/base/nsFrameManager.cpp +++ b/layout/base/nsFrameManager.cpp @@ -175,8 +175,9 @@ nsFrameManager::RegisterPlaceholderFrame(nsPlaceholderFrame* aPlaceholderFrame) PL_DHashTableInit(&mPlaceholderMap, &PlaceholderMapOps, sizeof(PlaceholderMapEntry)); } - PlaceholderMapEntry *entry = static_cast(PL_DHashTableAdd(&mPlaceholderMap, - aPlaceholderFrame->GetOutOfFlowFrame())); + PlaceholderMapEntry *entry = static_cast + (PL_DHashTableAdd(&mPlaceholderMap, + aPlaceholderFrame->GetOutOfFlowFrame(), fallible)); if (!entry) return NS_ERROR_OUT_OF_MEMORY; diff --git a/layout/style/nsCSSRuleProcessor.cpp b/layout/style/nsCSSRuleProcessor.cpp index 77bd60de2547..cda146e122e0 100644 --- a/layout/style/nsCSSRuleProcessor.cpp +++ b/layout/style/nsCSSRuleProcessor.cpp @@ -569,7 +569,7 @@ void RuleHash::AppendRuleToTable(PLDHashTable* aTable, const void* aKey, { // Get a new or existing entry. RuleHashTableEntry *entry = static_cast - (PL_DHashTableAdd(aTable, aKey)); + (PL_DHashTableAdd(aTable, aKey, fallible)); if (!entry) return; entry->mRules.AppendElement(RuleValue(aRuleInfo, mRuleCount++, mQuirksMode)); @@ -581,7 +581,7 @@ AppendRuleToTagTable(PLDHashTable* aTable, nsIAtom* aKey, { // Get a new or exisiting entry RuleHashTagTableEntry *entry = static_cast - (PL_DHashTableAdd(aTable, aKey)); + (PL_DHashTableAdd(aTable, aKey, fallible)); if (!entry) return; @@ -1035,7 +1035,7 @@ RuleCascadeData::AttributeListFor(nsIAtom* aAttribute) { AtomSelectorEntry *entry = static_cast - (PL_DHashTableAdd(&mAttributeSelectors, aAttribute)); + (PL_DHashTableAdd(&mAttributeSelectors, aAttribute, fallible)); if (!entry) return nullptr; return &entry->mSelectors; @@ -3128,9 +3128,8 @@ AddSelector(RuleCascadeData* aCascade, if (negation == aSelectorInTopLevel) { for (nsAtomList* curID = negation->mIDList; curID; curID = curID->mNext) { - AtomSelectorEntry *entry = - static_cast(PL_DHashTableAdd(&aCascade->mIdSelectors, - curID->mAtom)); + AtomSelectorEntry *entry = static_cast + (PL_DHashTableAdd(&aCascade->mIdSelectors, curID->mAtom, fallible)); if (entry) { entry->mSelectors.AppendElement(aSelectorInTopLevel); } @@ -3143,9 +3142,9 @@ AddSelector(RuleCascadeData* aCascade, if (negation == aSelectorInTopLevel) { for (nsAtomList* curClass = negation->mClassList; curClass; curClass = curClass->mNext) { - AtomSelectorEntry *entry = - static_cast(PL_DHashTableAdd(&aCascade->mClassSelectors, - curClass->mAtom)); + AtomSelectorEntry *entry = static_cast + (PL_DHashTableAdd(&aCascade->mClassSelectors, curClass->mAtom, + fallible)); if (entry) { entry->mSelectors.AppendElement(aSelectorInTopLevel); } @@ -3402,7 +3401,8 @@ CascadeRuleEnumFunc(css::Rule* aRule, void* aData) sel; sel = sel->mNext) { int32_t weight = sel->mWeight; RuleByWeightEntry *entry = static_cast( - PL_DHashTableAdd(&data->mRulesByWeight, NS_INT32_TO_PTR(weight))); + PL_DHashTableAdd(&data->mRulesByWeight, NS_INT32_TO_PTR(weight), + fallible)); if (!entry) return false; entry->data.mWeight = weight; diff --git a/layout/style/nsHTMLStyleSheet.cpp b/layout/style/nsHTMLStyleSheet.cpp index 672cb4a4ffba..913e07a8beaf 100644 --- a/layout/style/nsHTMLStyleSheet.cpp +++ b/layout/style/nsHTMLStyleSheet.cpp @@ -480,8 +480,9 @@ nsHTMLStyleSheet::UniqueMappedAttributes(nsMappedAttributes* aMapped) PL_DHashTableInit(&mMappedAttrTable, &MappedAttrTable_Ops, sizeof(MappedAttrTableEntry)); } - MappedAttrTableEntry *entry = static_cast - (PL_DHashTableAdd(&mMappedAttrTable, aMapped)); + MappedAttrTableEntry *entry = + static_cast + (PL_DHashTableAdd(&mMappedAttrTable, aMapped, fallible)); if (!entry) return nullptr; if (!entry->mAttributes) { @@ -515,7 +516,7 @@ nsHTMLStyleSheet::LangRuleFor(const nsString& aLanguage) sizeof(LangRuleTableEntry)); } LangRuleTableEntry *entry = static_cast - (PL_DHashTableAdd(&mLangRuleTable, &aLanguage)); + (PL_DHashTableAdd(&mLangRuleTable, &aLanguage, fallible)); if (!entry) { NS_ASSERTION(false, "out of memory"); return nullptr; diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index ff6dbdceb5cb..82a6a56b2bab 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -1533,7 +1533,7 @@ nsRuleNode::Transition(nsIStyleRule* aRule, uint8_t aLevel, if (ChildrenAreHashed()) { ChildrenHashEntry *entry = static_cast - (PL_DHashTableAdd(ChildrenHash(), &key)); + (PL_DHashTableAdd(ChildrenHash(), &key, fallible)); if (!entry) { NS_WARNING("out of memory"); return this; @@ -1611,7 +1611,7 @@ nsRuleNode::ConvertChildrenToHash(int32_t aNumKids) for (nsRuleNode* curr = ChildrenList(); curr; curr = curr->mNextSibling) { // This will never fail because of the initial size we gave the table. ChildrenHashEntry *entry = static_cast( - PL_DHashTableAdd(hash, curr->mRule)); + PL_DHashTableAdd(hash, curr->mRule, fallible)); NS_ASSERTION(!entry->mRuleNode, "duplicate entries in list"); entry->mRuleNode = curr; } diff --git a/layout/tables/SpanningCellSorter.cpp b/layout/tables/SpanningCellSorter.cpp index 8a4c015cb28f..63bc700bc4c9 100644 --- a/layout/tables/SpanningCellSorter.cpp +++ b/layout/tables/SpanningCellSorter.cpp @@ -75,7 +75,8 @@ SpanningCellSorter::AddCell(int32_t aColSpan, int32_t aRow, int32_t aCol) sizeof(HashTableEntry)); } HashTableEntry *entry = static_cast - (PL_DHashTableAdd(&mHashTable, NS_INT32_TO_PTR(aColSpan))); + (PL_DHashTableAdd(&mHashTable, NS_INT32_TO_PTR(aColSpan), + fallible)); NS_ENSURE_TRUE(entry, false); NS_ASSERTION(entry->mColSpan == 0 || entry->mColSpan == aColSpan, diff --git a/modules/libpref/prefapi.cpp b/modules/libpref/prefapi.cpp index d0ce8bef0e52..b099b2d845cb 100644 --- a/modules/libpref/prefapi.cpp +++ b/modules/libpref/prefapi.cpp @@ -740,7 +740,8 @@ nsresult pref_HashPref(const char *key, PrefValue value, PrefType type, uint32_t if (!gHashTable.IsInitialized()) return NS_ERROR_OUT_OF_MEMORY; - PrefHashEntry* pref = static_cast(PL_DHashTableAdd(&gHashTable, key)); + PrefHashEntry* pref = static_cast + (PL_DHashTableAdd(&gHashTable, key, fallible)); if (!pref) return NS_ERROR_OUT_OF_MEMORY; diff --git a/netwerk/base/nsLoadGroup.cpp b/netwerk/base/nsLoadGroup.cpp index e1fb5b0b912d..f6722a2caeeb 100644 --- a/netwerk/base/nsLoadGroup.cpp +++ b/netwerk/base/nsLoadGroup.cpp @@ -509,9 +509,8 @@ nsLoadGroup::AddRequest(nsIRequest *request, nsISupports* ctxt) // Add the request to the list of active requests... // - RequestMapEntry *entry = - static_cast - (PL_DHashTableAdd(&mRequests, request)); + RequestMapEntry *entry = static_cast + (PL_DHashTableAdd(&mRequests, request, fallible)); if (!entry) { return NS_ERROR_OUT_OF_MEMORY; diff --git a/netwerk/cache/nsCacheEntry.cpp b/netwerk/cache/nsCacheEntry.cpp index 7149bbfab687..7d405e7309ac 100644 --- a/netwerk/cache/nsCacheEntry.cpp +++ b/netwerk/cache/nsCacheEntry.cpp @@ -443,7 +443,7 @@ nsCacheEntryHashTable::AddEntry( nsCacheEntry *cacheEntry) if (!initialized) return NS_ERROR_NOT_INITIALIZED; if (!cacheEntry) return NS_ERROR_NULL_POINTER; - hashEntry = PL_DHashTableAdd(&table, &(cacheEntry->mKey)); + hashEntry = PL_DHashTableAdd(&table, &(cacheEntry->mKey), fallible); #ifndef DEBUG_dougt NS_ASSERTION(((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry == 0, "### nsCacheEntryHashTable::AddEntry - entry already used"); diff --git a/netwerk/cache/nsDiskCacheBinding.cpp b/netwerk/cache/nsDiskCacheBinding.cpp index ae735d7e05bb..637bb732a8c0 100644 --- a/netwerk/cache/nsDiskCacheBinding.cpp +++ b/netwerk/cache/nsDiskCacheBinding.cpp @@ -236,7 +236,8 @@ nsDiskCacheBindery::AddBinding(nsDiskCacheBinding * binding) HashTableEntry * hashEntry; hashEntry = (HashTableEntry *) PL_DHashTableAdd(&table, - (void *)(uintptr_t) binding->mRecord.HashNumber()); + (void *)(uintptr_t) binding->mRecord.HashNumber(), + fallible); if (!hashEntry) return NS_ERROR_OUT_OF_MEMORY; if (hashEntry->mBinding == nullptr) { diff --git a/netwerk/dns/nsHostResolver.cpp b/netwerk/dns/nsHostResolver.cpp index ef1fda880a75..a2cf6d7692ad 100644 --- a/netwerk/dns/nsHostResolver.cpp +++ b/netwerk/dns/nsHostResolver.cpp @@ -765,7 +765,7 @@ nsHostResolver::ResolveHost(const char *host, nsHostKey key = { host, flags, af }; nsHostDBEnt *he = static_cast - (PL_DHashTableAdd(&mDB, &key)); + (PL_DHashTableAdd(&mDB, &key, fallible)); // if the record is null, the hash table OOM'd. if (!he) { diff --git a/netwerk/protocol/http/nsHttp.cpp b/netwerk/protocol/http/nsHttp.cpp index 5f10195744e4..737968e08cfb 100644 --- a/netwerk/protocol/http/nsHttp.cpp +++ b/netwerk/protocol/http/nsHttp.cpp @@ -120,7 +120,7 @@ nsHttp::CreateAtomTable() for (int i = 0; atoms[i]; ++i) { PLDHashEntryStub *stub = reinterpret_cast - (PL_DHashTableAdd(&sAtomTable, atoms[i])); + (PL_DHashTableAdd(&sAtomTable, atoms[i], fallible)); if (!stub) return NS_ERROR_OUT_OF_MEMORY; @@ -168,7 +168,7 @@ nsHttp::ResolveAtom(const char *str) MutexAutoLock lock(*sLock); PLDHashEntryStub *stub = reinterpret_cast - (PL_DHashTableAdd(&sAtomTable, str)); + (PL_DHashTableAdd(&sAtomTable, str, fallible)); if (!stub) return atom; // out of memory diff --git a/parser/htmlparser/nsHTMLEntities.cpp b/parser/htmlparser/nsHTMLEntities.cpp index ad2cdf3123b2..97048f132f58 100644 --- a/parser/htmlparser/nsHTMLEntities.cpp +++ b/parser/htmlparser/nsHTMLEntities.cpp @@ -101,7 +101,7 @@ nsHTMLEntities::AddRefTable(void) // add to Entity->Unicode table EntityNodeEntry* entry = static_cast - (PL_DHashTableAdd(&gEntityToUnicode, node->mStr)); + (PL_DHashTableAdd(&gEntityToUnicode, node->mStr, fallible)); NS_ASSERTION(entry, "Error adding an entry"); // Prefer earlier entries when we have duplication. if (!entry->node) @@ -110,7 +110,8 @@ nsHTMLEntities::AddRefTable(void) // add to Unicode->Entity table entry = static_cast (PL_DHashTableAdd(&gUnicodeToEntity, - NS_INT32_TO_PTR(node->mUnicode))); + NS_INT32_TO_PTR(node->mUnicode), + fallible)); NS_ASSERTION(entry, "Error adding an entry"); // Prefer earlier entries when we have duplication. if (!entry->node) diff --git a/rdf/base/nsInMemoryDataSource.cpp b/rdf/base/nsInMemoryDataSource.cpp index 61de79fe6fc0..d09163583fe2 100644 --- a/rdf/base/nsInMemoryDataSource.cpp +++ b/rdf/base/nsInMemoryDataSource.cpp @@ -332,7 +332,8 @@ public: void SetForwardArcs(nsIRDFResource* u, Assertion* as) { if (as) { - Entry* entry = static_cast(PL_DHashTableAdd(&mForwardArcs, u)); + Entry* entry = static_cast + (PL_DHashTableAdd(&mForwardArcs, u, mozilla::fallible)); if (entry) { entry->mNode = u; entry->mAssertions = as; @@ -346,7 +347,8 @@ public: void SetReverseArcs(nsIRDFNode* v, Assertion* as) { if (as) { - Entry* entry = static_cast(PL_DHashTableAdd(&mReverseArcs, v)); + Entry* entry = static_cast + (PL_DHashTableAdd(&mReverseArcs, v, mozilla::fallible)); if (entry) { entry->mNode = v; entry->mAssertions = as; @@ -1184,7 +1186,8 @@ InMemoryDataSource::LockedAssert(nsIRDFResource* aSource, } else { - hdr = PL_DHashTableAdd(next->u.hash.mPropertyHash, aProperty); + hdr = PL_DHashTableAdd(next->u.hash.mPropertyHash, aProperty, + mozilla::fallible); if (hdr) { Entry* entry = static_cast(hdr); @@ -1295,8 +1298,9 @@ InMemoryDataSource::LockedUnassert(nsIRDFResource* aSource, PL_DHashTableRawRemove(root->u.hash.mPropertyHash, hdr); if (next && next->mNext) { - PLDHashEntryHdr* hdr = PL_DHashTableAdd(root->u.hash.mPropertyHash, - aProperty); + PLDHashEntryHdr* hdr = + PL_DHashTableAdd(root->u.hash.mPropertyHash, aProperty, + mozilla::fallible); if (hdr) { Entry* entry = static_cast(hdr); entry->mNode = aProperty; @@ -1740,7 +1744,8 @@ InMemoryDataSource::EnsureFastContainment(nsIRDFResource* aSource) val->mNext = first; } else { - PLDHashEntryHdr* hdr = PL_DHashTableAdd(table, prop); + PLDHashEntryHdr* hdr = PL_DHashTableAdd(table, prop, + mozilla::fallible); if (hdr) { Entry* entry = static_cast(hdr); entry->mNode = prop; diff --git a/rdf/base/nsRDFService.cpp b/rdf/base/nsRDFService.cpp index ffce7a6cad3d..1d539d395f19 100644 --- a/rdf/base/nsRDFService.cpp +++ b/rdf/base/nsRDFService.cpp @@ -1162,7 +1162,7 @@ RDFServiceImpl::RegisterResource(nsIRDFResource* aResource, bool aReplace) aResource, (const char*) uri)); } else { - hdr = PL_DHashTableAdd(&mResources, uri); + hdr = PL_DHashTableAdd(&mResources, uri, fallible); if (! hdr) return NS_ERROR_OUT_OF_MEMORY; @@ -1399,7 +1399,7 @@ RDFServiceImpl::RegisterLiteral(nsIRDFLiteral* aLiteral) NS_ASSERTION(!PL_DHashTableSearch(&mLiterals, value), "literal already registered"); - PLDHashEntryHdr *hdr = PL_DHashTableAdd(&mLiterals, value); + PLDHashEntryHdr *hdr = PL_DHashTableAdd(&mLiterals, value, fallible); if (! hdr) return NS_ERROR_OUT_OF_MEMORY; @@ -1451,7 +1451,7 @@ RDFServiceImpl::RegisterInt(nsIRDFInt* aInt) NS_ASSERTION(!PL_DHashTableSearch(&mInts, &value), "int already registered"); - PLDHashEntryHdr *hdr = PL_DHashTableAdd(&mInts, &value); + PLDHashEntryHdr *hdr = PL_DHashTableAdd(&mInts, &value, fallible); if (! hdr) return NS_ERROR_OUT_OF_MEMORY; @@ -1503,7 +1503,7 @@ RDFServiceImpl::RegisterDate(nsIRDFDate* aDate) NS_ASSERTION(!PL_DHashTableSearch(&mDates, &value), "date already registered"); - PLDHashEntryHdr *hdr = PL_DHashTableAdd(&mDates, &value); + PLDHashEntryHdr *hdr = PL_DHashTableAdd(&mDates, &value, fallible); if (! hdr) return NS_ERROR_OUT_OF_MEMORY; @@ -1550,7 +1550,7 @@ RDFServiceImpl::RegisterBlob(BlobImpl *aBlob) NS_ASSERTION(!PL_DHashTableSearch(&mBlobs, &aBlob->mData), "blob already registered"); - PLDHashEntryHdr *hdr = PL_DHashTableAdd(&mBlobs, &aBlob->mData); + PLDHashEntryHdr *hdr = PL_DHashTableAdd(&mBlobs, &aBlob->mData, fallible); if (! hdr) return NS_ERROR_OUT_OF_MEMORY; diff --git a/security/manager/boot/src/nsSecureBrowserUIImpl.cpp b/security/manager/boot/src/nsSecureBrowserUIImpl.cpp index e9c9aec78d5f..3e48dac8accf 100644 --- a/security/manager/boot/src/nsSecureBrowserUIImpl.cpp +++ b/security/manager/boot/src/nsSecureBrowserUIImpl.cpp @@ -860,8 +860,8 @@ nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress, // means, there has already been data transfered. ReentrantMonitorAutoEnter lock(mReentrantMonitor); - PL_DHashTableAdd(&mTransferringRequests, aRequest); - + PL_DHashTableAdd(&mTransferringRequests, aRequest, fallible); + return NS_OK; } diff --git a/security/manager/ssl/src/nsCertTree.cpp b/security/manager/ssl/src/nsCertTree.cpp index b0be2621cdfa..45611d8bf882 100644 --- a/security/manager/ssl/src/nsCertTree.cpp +++ b/security/manager/ssl/src/nsCertTree.cpp @@ -199,9 +199,8 @@ CompareCacheHashEntry * nsCertTree::getCacheEntry(void *cache, void *aCert) { PLDHashTable &aCompareCache = *reinterpret_cast(cache); - CompareCacheHashEntryPtr *entryPtr = - static_cast - (PL_DHashTableAdd(&aCompareCache, aCert)); + CompareCacheHashEntryPtr *entryPtr = static_cast + (PL_DHashTableAdd(&aCompareCache, aCert, fallible)); return entryPtr ? entryPtr->entry : nullptr; } diff --git a/security/manager/ssl/src/nsNSSShutDown.cpp b/security/manager/ssl/src/nsNSSShutDown.cpp index f720246fef81..311902af88cf 100644 --- a/security/manager/ssl/src/nsNSSShutDown.cpp +++ b/security/manager/ssl/src/nsNSSShutDown.cpp @@ -68,7 +68,7 @@ void nsNSSShutDownList::remember(nsNSSShutDownObject *o) PR_ASSERT(o); MutexAutoLock lock(singleton->mListLock); - PL_DHashTableAdd(&singleton->mObjects, o); + PL_DHashTableAdd(&singleton->mObjects, o, fallible); } void nsNSSShutDownList::forget(nsNSSShutDownObject *o) @@ -88,7 +88,7 @@ void nsNSSShutDownList::remember(nsOnPK11LogoutCancelObject *o) PR_ASSERT(o); MutexAutoLock lock(singleton->mListLock); - PL_DHashTableAdd(&singleton->mPK11LogoutCancelObjects, o); + PL_DHashTableAdd(&singleton->mPK11LogoutCancelObjects, o, fallible); } void nsNSSShutDownList::forget(nsOnPK11LogoutCancelObject *o) diff --git a/uriloader/base/nsDocLoader.cpp b/uriloader/base/nsDocLoader.cpp index 8e7ffa76b7ff..8a0e77735ae9 100644 --- a/uriloader/base/nsDocLoader.cpp +++ b/uriloader/base/nsDocLoader.cpp @@ -1338,7 +1338,7 @@ nsDocLoader::RefreshAttempted(nsIWebProgress* aWebProgress, nsresult nsDocLoader::AddRequestInfo(nsIRequest *aRequest) { - if (!PL_DHashTableAdd(&mRequestInfoHash, aRequest)) { + if (!PL_DHashTableAdd(&mRequestInfoHash, aRequest, mozilla::fallible)) { return NS_ERROR_OUT_OF_MEMORY; } diff --git a/xpcom/base/nsCycleCollector.cpp b/xpcom/base/nsCycleCollector.cpp index e6237922b193..1ea03cdc62a9 100644 --- a/xpcom/base/nsCycleCollector.cpp +++ b/xpcom/base/nsCycleCollector.cpp @@ -900,8 +900,8 @@ PtrToNodeEntry* CCGraph::AddNodeToMap(void* aPtr) { JS::AutoSuppressGCAnalysis suppress; - PtrToNodeEntry* e = - static_cast(PL_DHashTableAdd(&mPtrToNodeMap, aPtr)); + PtrToNodeEntry* e = static_cast + (PL_DHashTableAdd(&mPtrToNodeMap, aPtr, fallible)); if (!e) { // Caller should track OOMs return nullptr; diff --git a/xpcom/ds/nsAtomTable.cpp b/xpcom/ds/nsAtomTable.cpp index 046dac07b22c..c4d818d1ac7a 100644 --- a/xpcom/ds/nsAtomTable.cpp +++ b/xpcom/ds/nsAtomTable.cpp @@ -553,12 +553,8 @@ GetAtomHashEntry(const char* aString, uint32_t aLength, uint32_t* aHashOut) MOZ_ASSERT(NS_IsMainThread(), "wrong thread"); EnsureTableExists(); AtomTableKey key(aString, aLength, aHashOut); - AtomTableEntry* e = static_cast( - PL_DHashTableAdd(&gAtomTable, &key)); - if (!e) { - NS_ABORT_OOM(gAtomTable.EntryCount() * gAtomTable.EntrySize()); - } - return e; + // This is an infallible add. + return static_cast(PL_DHashTableAdd(&gAtomTable, &key)); } static inline AtomTableEntry* @@ -567,12 +563,8 @@ GetAtomHashEntry(const char16_t* aString, uint32_t aLength, uint32_t* aHashOut) MOZ_ASSERT(NS_IsMainThread(), "wrong thread"); EnsureTableExists(); AtomTableKey key(aString, aLength, aHashOut); - AtomTableEntry* e = static_cast( - PL_DHashTableAdd(&gAtomTable, &key)); - if (!e) { - NS_ABORT_OOM(gAtomTable.EntryCount() * gAtomTable.EntrySize()); - } - return e; + // This is an infallible add. + return static_cast(PL_DHashTableAdd(&gAtomTable, &key)); } class CheckStaticAtomSizes diff --git a/xpcom/ds/nsPersistentProperties.cpp b/xpcom/ds/nsPersistentProperties.cpp index 8584fa0d9194..e99675593850 100644 --- a/xpcom/ds/nsPersistentProperties.cpp +++ b/xpcom/ds/nsPersistentProperties.cpp @@ -528,7 +528,7 @@ nsPersistentProperties::SetStringProperty(const nsACString& aKey, { const nsAFlatCString& flatKey = PromiseFlatCString(aKey); PropertyTableEntry* entry = static_cast( - PL_DHashTableAdd(&mTable, flatKey.get())); + PL_DHashTableAdd(&mTable, flatKey.get(), mozilla::fallible)); if (entry->mKey) { aOldValue = entry->mValue; diff --git a/xpcom/ds/nsStaticNameTable.cpp b/xpcom/ds/nsStaticNameTable.cpp index 6d8950cf15e3..aa95c23464b2 100644 --- a/xpcom/ds/nsStaticNameTable.cpp +++ b/xpcom/ds/nsStaticNameTable.cpp @@ -164,8 +164,8 @@ nsStaticCaseInsensitiveNameTable::Init(const char* const aNames[], NameTableKey key(strPtr); - NameTableEntry* entry = - static_cast(PL_DHashTableAdd(&mNameTable, &key)); + NameTableEntry* entry = static_cast + (PL_DHashTableAdd(&mNameTable, &key, fallible)); if (!entry) { continue; } diff --git a/xpcom/glue/nsTHashtable.h b/xpcom/glue/nsTHashtable.h index dc729bac58fe..5718054cba11 100644 --- a/xpcom/glue/nsTHashtable.h +++ b/xpcom/glue/nsTHashtable.h @@ -149,19 +149,21 @@ public: */ EntryType* PutEntry(KeyType aKey) { - EntryType* e = PutEntry(aKey, mozilla::fallible); - if (!e) { - NS_ABORT_OOM(mTable.EntrySize() * mTable.EntryCount()); - } - return e; - } - - EntryType* PutEntry(KeyType aKey, const fallible_t&) NS_WARN_UNUSED_RESULT { NS_ASSERTION(mTable.IsInitialized(), "nsTHashtable was not initialized properly."); - return static_cast(PL_DHashTableAdd( - &mTable, EntryType::KeyToPointer(aKey))); + return static_cast // infallible add + (PL_DHashTableAdd(&mTable, EntryType::KeyToPointer(aKey))); + } + + EntryType* PutEntry(KeyType aKey, const fallible_t&) NS_WARN_UNUSED_RESULT + { + NS_ASSERTION(mTable.IsInitialized(), + "nsTHashtable was not initialized properly."); + + return static_cast + (PL_DHashTableAdd(&mTable, EntryType::KeyToPointer(aKey), + mozilla::fallible)); } /** diff --git a/xpcom/glue/pldhash.cpp b/xpcom/glue/pldhash.cpp index b816ddb3d921..51c660e38c82 100644 --- a/xpcom/glue/pldhash.cpp +++ b/xpcom/glue/pldhash.cpp @@ -570,7 +570,7 @@ PLDHashTable::Search(const void* aKey) } MOZ_ALWAYS_INLINE PLDHashEntryHdr* -PLDHashTable::Add(const void* aKey) +PLDHashTable::Add(const void* aKey, const mozilla::fallible_t&) { PLDHashNumber keyHash; PLDHashEntryHdr* entry; @@ -671,10 +671,24 @@ PL_DHashTableSearch(PLDHashTable* aTable, const void* aKey) return aTable->Search(aKey); } +PLDHashEntryHdr* PL_DHASH_FASTCALL +PL_DHashTableAdd(PLDHashTable* aTable, const void* aKey, + const fallible_t& aFallible) +{ + return aTable->Add(aKey, aFallible); +} + PLDHashEntryHdr* PL_DHASH_FASTCALL PL_DHashTableAdd(PLDHashTable* aTable, const void* aKey) { - return aTable->Add(aKey); + PLDHashEntryHdr* entry = PL_DHashTableAdd(aTable, aKey, fallible); + if (!entry) { + // There are two ways the Add could fail: (a) a entry storage reallocation + // failed, or (b) mOps->initEntry failed. The number we're reporting here + // is the one for case (a), which is the more likely of the two. + NS_ABORT_OOM(aTable->EntrySize() * aTable->EntryCount()); + } + return entry; } void PL_DHASH_FASTCALL diff --git a/xpcom/glue/pldhash.h b/xpcom/glue/pldhash.h index 365e8d8c699f..5c04a1b769e6 100644 --- a/xpcom/glue/pldhash.h +++ b/xpcom/glue/pldhash.h @@ -244,7 +244,7 @@ public: void Finish(); PLDHashEntryHdr* Search(const void* aKey); - PLDHashEntryHdr* Add(const void* aKey); + PLDHashEntryHdr* Add(const void* aKey, const mozilla::fallible_t&); void Remove(const void* aKey); void RawRemove(PLDHashEntryHdr* aEntry); @@ -481,7 +481,7 @@ PL_DHashTableSearch(PLDHashTable* aTable, const void* aKey); /* * To add an entry identified by key to table, call: * - * entry = PL_DHashTableAdd(table, key); + * entry = PL_DHashTableAdd(table, key, mozilla::fallible); * * If entry is null upon return, then either (a) the table is severely * overloaded and memory can't be allocated for entry storage, or (b) @@ -495,6 +495,14 @@ PL_DHashTableSearch(PLDHashTable* aTable, const void* aKey); * optional initEntry hook was not used). */ PLDHashEntryHdr* PL_DHASH_FASTCALL +PL_DHashTableAdd(PLDHashTable* aTable, const void* aKey, + const mozilla::fallible_t&); + +/* + * This is like the other PL_DHashTableAdd() function, but infallible, and so + * never returns null. + */ +PLDHashEntryHdr* PL_DHASH_FASTCALL PL_DHashTableAdd(PLDHashTable* aTable, const void* aKey); /* diff --git a/xpcom/tests/TestPLDHash.cpp b/xpcom/tests/TestPLDHash.cpp index fdb6ea5bbfef..cac6ace55558 100644 --- a/xpcom/tests/TestPLDHash.cpp +++ b/xpcom/tests/TestPLDHash.cpp @@ -138,7 +138,7 @@ static bool test_pldhash_grow_to_max_capacity() // Keep inserting elements until failure occurs because the table is full. size_t numInserted = 0; while (true) { - if (!PL_DHashTableAdd(t, (const void*)numInserted)) { + if (!PL_DHashTableAdd(t, (const void*)numInserted, mozilla::fallible)) { break; } numInserted++;