Added kUnboundedSize (~0) to specify unlimited capacity instead of using 0.
Trimming a quarantine with max size 0 should flush it.
BUG=
R=chrisha@chromium.org

Review URL: https://codereview.appspot.com/139830043

git-svn-id: http://sawbuck.googlecode.com/svn/trunk@2287 15e8cca8-e42c-11de-a347-f34a4f72eb7d
diff --git a/syzygy/agent/asan/quarantines/sharded_quarantine_unittest.cc b/syzygy/agent/asan/quarantines/sharded_quarantine_unittest.cc
index fc37965..cba6039 100644
--- a/syzygy/agent/asan/quarantines/sharded_quarantine_unittest.cc
+++ b/syzygy/agent/asan/quarantines/sharded_quarantine_unittest.cc
@@ -76,7 +76,7 @@
   DummyObject popped;
 
   // No max object size. This logic is tested in SizeLimitedQuarantineImpl.
-  q.set_max_object_size(0);
+  q.set_max_object_size(TestShardedQuarantine::kUnboundedSize);
   q.set_max_quarantine_size(10000);
 
   EXPECT_EQ(0u, q.size());
diff --git a/syzygy/agent/asan/quarantines/size_limited_quarantine.h b/syzygy/agent/asan/quarantines/size_limited_quarantine.h
index 5e56895..3aef59f 100644
--- a/syzygy/agent/asan/quarantines/size_limited_quarantine.h
+++ b/syzygy/agent/asan/quarantines/size_limited_quarantine.h
@@ -51,19 +51,25 @@
  public:
   typedef SizeFunctorType SizeFunctor;
 
-  // Constructor. Initializes all sizes to zero so the quarantine will
-  // block all objects from entering initially.
+  static const size_t kUnboundedSize = ~0;
+
+  // Constructor. Initially the quarantine has unlimited capacity.
   SizeLimitedQuarantineImpl()
-      : max_object_size_(0), max_quarantine_size_(0), size_(0), count_(0),
+      : max_object_size_(kUnboundedSize),
+        max_quarantine_size_(kUnboundedSize),
+        size_(0),
+        count_(0),
         size_functor_() {
   }
 
-  // Constructor. Initializes all sizes to zero so the quarantine will
-  // block all objects from entering initially.
+  // Constructor. Initially the quarantine has unlimited capacity.
   // @param size_functor The size functor to be used. This will be copied
   //     into the classes member size functor.
   explicit SizeLimitedQuarantineImpl(const SizeFunctor& size_functor)
-      : max_object_size_(0), max_quarantine_size_(0), size_(0), count_(0),
+      : max_object_size_(kUnboundedSize),
+        max_quarantine_size_(kUnboundedSize),
+        size_(0),
+        count_(0),
         size_functor_(size_functor) {
   }
 
@@ -74,7 +80,7 @@
   // objects to 'Push', and does not invalidate overly objects already in
   // the quarantine.
   // @param max_object_size The maximum size of any single object in the
-  //     quarantine. A size of 0 means unlimited (no max).
+  //     quarantine. Use kUnboundedSize for unlimited (no max).
   void set_max_object_size(size_t max_object_size) {
     max_object_size_ = max_object_size;
   }
@@ -82,7 +88,7 @@
   // Sets the maximum quarantine size. This may cause the quarantine
   // invariant to be immediately invalidated, requiring calls to 'Pop'.
   // @param max_quarantine_size The maximum size of the entire quarantine.
-  //     A size of 0 means unlimited (no max).
+  //     Use kUnboundedSize for unlimited (no max).
   void set_max_quarantine_size(size_t max_quarantine_size) {
     max_quarantine_size_ = max_quarantine_size;
   }
diff --git a/syzygy/agent/asan/quarantines/size_limited_quarantine_impl.h b/syzygy/agent/asan/quarantines/size_limited_quarantine_impl.h
index 74c5ae9..085578b 100644
--- a/syzygy/agent/asan/quarantines/size_limited_quarantine_impl.h
+++ b/syzygy/agent/asan/quarantines/size_limited_quarantine_impl.h
@@ -27,9 +27,9 @@
     const Object& object) {
   SizeFunctor get_size;
   size_t size = get_size(object);
-  if (max_object_size_ != 0 && size > max_object_size_)
+  if (max_object_size_ != kUnboundedSize && size > max_object_size_)
     return false;
-  if (max_quarantine_size_ != 0 && size > max_quarantine_size_)
+  if (max_quarantine_size_ != kUnboundedSize && size > max_quarantine_size_)
     return false;
   if (!PushImpl(object))
     return false;
@@ -42,7 +42,8 @@
 bool SizeLimitedQuarantineImpl<OT, SFT>::Pop(
     Object* object) {
   DCHECK_NE(static_cast<Object*>(NULL), object);
-  if (max_quarantine_size_ == 0 || size_ <= max_quarantine_size_)
+  if (max_quarantine_size_ == kUnboundedSize ||
+      size_ <= max_quarantine_size_)
     return false;
   PopImpl(object);
   SizeFunctor get_size;
diff --git a/syzygy/agent/asan/quarantines/size_limited_quarantine_unittest.cc b/syzygy/agent/asan/quarantines/size_limited_quarantine_unittest.cc
index c6ccff2..f158c8f 100644
--- a/syzygy/agent/asan/quarantines/size_limited_quarantine_unittest.cc
+++ b/syzygy/agent/asan/quarantines/size_limited_quarantine_unittest.cc
@@ -84,8 +84,8 @@
 
 TEST(SizeLimitedQuarantineTest, ConstructorsSettersAndGetters) {
   TestQuarantine q;
-  EXPECT_EQ(0u, q.max_object_size());
-  EXPECT_EQ(0u, q.max_quarantine_size());
+  EXPECT_EQ(TestQuarantine::kUnboundedSize, q.max_object_size());
+  EXPECT_EQ(TestQuarantine::kUnboundedSize, q.max_quarantine_size());
   EXPECT_EQ(0u, q.size());
   EXPECT_EQ(0u, q.GetCount());