Bug 1173212 (part 2) - Make PLDHashTable::Iterator work in chaos mode. r=froydnj.

Iterator::NextEntry() miscomputes |entryLimit|. This doesn't matter in
non-chaos mode because we'll always find a live entry before hitting that
limit. But it does matter in chaos mode because it means we don't wrap around
when we should.

It's clear how this mistake was made -- the code from Enumerate() was copied.
In Enumerate() |mEntryStore| and |entryAddr| are the same when |entryLimit| is
computed, so you can use them interchangeably. But in NextEntry() |mEntryAddr|
will have moved past |mEntryStore|, so you have to use |mEntryStore|. I changed
both functions in the same way to keep the correspondence between them obvious.
This commit is contained in:
Nicholas Nethercote 2015-06-10 12:47:18 -07:00
parent a02aa73be7
commit 5d7a320705

View File

@ -759,7 +759,7 @@ PLDHashTable::Enumerate(PLDHashEnumerator aEtor, void* aArg)
char* entryAddr = mEntryStore;
uint32_t capacity = Capacity();
uint32_t tableSize = capacity * mEntrySize;
char* entryLimit = entryAddr + tableSize;
char* entryLimit = mEntryStore + tableSize;
uint32_t i = 0;
bool didRemove = false;
@ -954,7 +954,7 @@ PLDHashTable::Iterator::NextEntry()
// mEntryAddr, respectively.
uint32_t capacity = mTable->Capacity();
uint32_t tableSize = capacity * mTable->mEntrySize;
char* entryLimit = mEntryAddr + tableSize;
char* entryLimit = mTable->mEntryStore + tableSize;
// Strictly speaking, we don't need to iterate over the full capacity each
// time. However, it is simpler to do so rather than unnecessarily track the