diff --git a/xpcom/base/nsCycleCollector.cpp b/xpcom/base/nsCycleCollector.cpp index 98f1041d9580..91cd2d77b4ba 100644 --- a/xpcom/base/nsCycleCollector.cpp +++ b/xpcom/base/nsCycleCollector.cpp @@ -613,7 +613,9 @@ public: class NodePool { private: - enum { BlockSize = 8 * 1024 }; // could be int template parameter + // The -2 allows us to use |BlockSize + 1| for |mEntries|, and fit |mNext|, + // all without causing slop. + enum { BlockSize = 8 * 1024 - 2 }; struct Block { @@ -623,6 +625,13 @@ private: Block() { NS_NOTREACHED("should never be called"); + + // Ensure Block is the right size (see the comment on BlockSize above). + static_assert( + sizeof(Block) == 163824 || // 32-bit; equals 39.997 pages + sizeof(Block) == 262120, // 64-bit; equals 63.994 pages + "ill-sized NodePool::Block" + ); } ~Block() {