Bug 1174046 - Fix PLDHashTable::Iterator in chaos mode again. r=froydnj, a=philor
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 11 Jun 2015 18:23:26 -0700
changeset 248463 0093691d37157330d439e2b0d5999a95ab22ff96
parent 248462 c2a414f8bd73d5c588e223cf9f36b8e5507818cb
child 248481 20708c7759e3530121c120f2c1ff640a3ab800a7
child 248517 02a04654e99466534ed92c6d646e5883f83538ef
push id28896
push userphilringnalda@gmail.com
push dateFri, 12 Jun 2015 04:31:57 +0000
treeherdermozilla-central@0093691d3715 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj, philor
bugs1174046
milestone41.0a1
first release with
nightly linux32
0093691d3715 / 41.0a1 / 20150612030205 / files
nightly linux64
0093691d3715 / 41.0a1 / 20150612030205 / files
nightly mac
0093691d3715 / 41.0a1 / 20150612030205 / files
nightly win32
0093691d3715 / 41.0a1 / 20150612030205 / files
nightly win64
0093691d3715 / 41.0a1 / 20150612030205 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1174046 - Fix PLDHashTable::Iterator in chaos mode again. r=froydnj, a=philor CLOSED TREE If you use PLDHashTable::Iterator in chaos mode with a table with zero capacity, a |% 0| operation takes place in randomUint32LessThan. This change avoids that.
mfbt/ChaosMode.h
xpcom/glue/pldhash.cpp
--- a/mfbt/ChaosMode.h
+++ b/mfbt/ChaosMode.h
@@ -76,15 +76,16 @@ public:
   }
 
   /**
    * Returns a somewhat (but not uniformly) random uint32_t < aBound.
    * Not to be used for anything except ChaosMode, since it's not very random.
    */
   static uint32_t randomUint32LessThan(uint32_t aBound)
   {
+    MOZ_ASSERT(aBound != 0);
     return uint32_t(rand()) % aBound;
   }
 };
 
 } /* namespace mozilla */
 
 #endif /* mozilla_ChaosMode_h */
--- a/xpcom/glue/pldhash.cpp
+++ b/xpcom/glue/pldhash.cpp
@@ -905,17 +905,17 @@ PLDHashTable::Iterator::Iterator(const P
   INCREMENT_RECURSION_LEVEL(mTable);
 
   // The following code is taken from, and should be kept in sync with, the
   // PLDHashTable::Enumerate method above. The variables i and entryAddr (which
   // vary over the course of the for loop) are converted into mEntryOffset and
   // mEntryAddr, respectively.
   uint32_t capacity = mTable->Capacity();
 
-  if (ChaosMode::isActive(ChaosMode::HashTableIteration)) {
+  if (ChaosMode::isActive(ChaosMode::HashTableIteration) && capacity > 0) {
     // Start iterating at a random point in the hashtable. It would be
     // even more chaotic to iterate in fully random order, but that's a lot
     // more work.
     mEntryAddr += ChaosMode::randomUint32LessThan(capacity) * mTable->mEntrySize;
   }
 }
 
 PLDHashTable::Iterator::Iterator(const Iterator& aIterator)