diff --git a/dom/base/nsContentList.cpp b/dom/base/nsContentList.cpp index 9d9dc76509b..7a4a0f2d3ea 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 63dacabbb11..311205c8f5e 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -3960,7 +3960,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 7e159ebf9a3..b45292183c7 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -3990,9 +3990,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 0dec88123e8..13e42240b46 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 eab3042bfbc..e0d12f9b4c7 100644 --- a/dom/base/nsScriptNameSpaceManager.cpp +++ b/dom/base/nsScriptNameSpaceManager.cpp @@ -139,9 +139,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 562fde7fec7..874fe228ddc 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 ac978f45cd1..ee8d956cf89 100644 --- a/dom/xul/XULDocument.cpp +++ b/dom/xul/XULDocument.cpp @@ -778,9 +778,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 253dbbe989b..f61a09027a7 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 e87faa41086..71203f55974 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 2bfc80e670c..cc36ee2c8f0 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 471cdb5900c..6acb34511cd 100644 --- a/gfx/thebes/gfxFT2FontList.cpp +++ b/gfx/thebes/gfxFT2FontList.cpp @@ -687,9 +687,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; @@ -736,9 +735,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 d5c5b4f81e2..ad4339d4248 100644 --- a/js/xpconnect/src/XPCMaps.cpp +++ b/js/xpconnect/src/XPCMaps.cpp @@ -593,7 +593,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 413fe93065b..5a8f4720377 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 d34d0e58165..7b43cffd555 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 a2126e26624..d6b0497df34 100644 --- a/layout/style/nsCSSRuleProcessor.cpp +++ b/layout/style/nsCSSRuleProcessor.cpp @@ -573,7 +573,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)); @@ -585,7 +585,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; @@ -1041,7 +1041,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; @@ -3134,9 +3134,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); } @@ -3149,9 +3148,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); } @@ -3410,7 +3409,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 47ead13ef41..1e80cdcd90d 100644 --- a/layout/style/nsHTMLStyleSheet.cpp +++ b/layout/style/nsHTMLStyleSheet.cpp @@ -483,8 +483,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) { @@ -518,7 +519,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 f7831ee6025..78c7c6150e9 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -1535,7 +1535,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 8a4c015cb28..63bc700bc4c 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 00f3079a6bd..475791a0284 100644 --- a/modules/libpref/prefapi.cpp +++ b/modules/libpref/prefapi.cpp @@ -735,7 +735,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 f9566558dba..4fd4075013d 100644 --- a/netwerk/base/nsLoadGroup.cpp +++ b/netwerk/base/nsLoadGroup.cpp @@ -511,9 +511,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 46dcdf87034..2e9d50355b6 100644 --- a/netwerk/cache/nsCacheEntry.cpp +++ b/netwerk/cache/nsCacheEntry.cpp @@ -435,7 +435,7 @@ nsCacheEntryHashTable::AddEntry( nsCacheEntry *cacheEntry) if (!table.IsInitialized()) 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 ae735d7e05b..637bb732a8c 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 f238294fe08..79fa275d724 100644 --- a/netwerk/dns/nsHostResolver.cpp +++ b/netwerk/dns/nsHostResolver.cpp @@ -764,7 +764,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 79eeb3c6ee7..43f014ab0c6 100644 --- a/netwerk/protocol/http/nsHttp.cpp +++ b/netwerk/protocol/http/nsHttp.cpp @@ -118,7 +118,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; @@ -166,7 +166,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 74bfc3eb888..84138fc6f68 100644 --- a/parser/htmlparser/nsHTMLEntities.cpp +++ b/parser/htmlparser/nsHTMLEntities.cpp @@ -94,7 +94,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) @@ -103,7 +103,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 61a3fc07880..04be3ade4d8 100644 --- a/rdf/base/nsInMemoryDataSource.cpp +++ b/rdf/base/nsInMemoryDataSource.cpp @@ -334,7 +334,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; @@ -348,7 +349,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; @@ -1186,7 +1188,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); @@ -1297,8 +1300,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; @@ -1742,7 +1746,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 ffce7a6cad3..1d539d395f1 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 a5b6bd9907d..0d5354ea3da 100644 --- a/security/manager/boot/src/nsSecureBrowserUIImpl.cpp +++ b/security/manager/boot/src/nsSecureBrowserUIImpl.cpp @@ -862,8 +862,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 2de29024414..3f5e8c860bb 100644 --- a/security/manager/ssl/src/nsCertTree.cpp +++ b/security/manager/ssl/src/nsCertTree.cpp @@ -201,9 +201,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 f20490673ae..5c4605edb5c 100644 --- a/security/manager/ssl/src/nsNSSShutDown.cpp +++ b/security/manager/ssl/src/nsNSSShutDown.cpp @@ -70,7 +70,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) @@ -90,7 +90,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 ae724bc34ba..3e6252beaa8 100644 --- a/uriloader/base/nsDocLoader.cpp +++ b/uriloader/base/nsDocLoader.cpp @@ -1340,7 +1340,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 30077dd8ed3..594567f3ccc 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 ae3bda994ad..7bdc13a0aa6 100644 --- a/xpcom/ds/nsAtomTable.cpp +++ b/xpcom/ds/nsAtomTable.cpp @@ -556,12 +556,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* @@ -570,12 +566,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 8584fa0d919..e9967559385 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 db5091e8fac..d057b1233f5 100644 --- a/xpcom/ds/nsStaticNameTable.cpp +++ b/xpcom/ds/nsStaticNameTable.cpp @@ -161,8 +161,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 2a0d5dc5e0d..cd582d8f0e1 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 d284d1ec242..62fa59ccdf5 100644 --- a/xpcom/glue/pldhash.cpp +++ b/xpcom/glue/pldhash.cpp @@ -529,7 +529,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; @@ -647,10 +647,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 e820aa067a9..a549c3cebeb 100644 --- a/xpcom/glue/pldhash.h +++ b/xpcom/glue/pldhash.h @@ -10,6 +10,7 @@ * Double hashing, a la Knuth 6. */ #include "mozilla/Attributes.h" // for MOZ_ALWAYS_INLINE +#include "mozilla/fallible.h" #include "mozilla/MemoryReporting.h" #include "mozilla/Types.h" #include "nscore.h" @@ -244,7 +245,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); @@ -466,7 +467,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) @@ -480,6 +481,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 3b56e367b62..83851217c36 100644 --- a/xpcom/tests/TestPLDHash.cpp +++ b/xpcom/tests/TestPLDHash.cpp @@ -139,7 +139,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++;