Put hard CHECKS() in fxcrt::Retainable

Guard against mistakes like, say, a program repeatedly
calling .Leak().

-- convert to unsigned representation.

Change-Id: If3338d9fb7eeea578caec0668da64031abf6c54f
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/101992
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcrt/retain_ptr.h b/core/fxcrt/retain_ptr.h
index 5b88a66..26223b6 100644
--- a/core/fxcrt/retain_ptr.h
+++ b/core/fxcrt/retain_ptr.h
@@ -177,14 +177,20 @@
   // These need to be const methods operating on a mutable member so that
   // RetainPtr<const T> can be used for an object that is otherwise const
   // apart from the internal ref-counting.
-  void Retain() const { ++m_nRefCount; }
+  void Retain() const {
+    ++m_nRefCount;
+    CHECK(m_nRefCount > 0);
+  }
   void Release() const {
-    DCHECK(m_nRefCount > 0);
+    CHECK(m_nRefCount > 0);
     if (--m_nRefCount == 0)
       delete this;
   }
 
-  mutable intptr_t m_nRefCount = 0;
+  mutable uintptr_t m_nRefCount = 0;
+  static_assert(std::is_unsigned<decltype(m_nRefCount)>::value,
+                "m_nRefCount must be an unsigned type for overflow check"
+                "to work properly in Retain()");
 };
 
 }  // namespace fxcrt