Add CHECK_LT() et al. to PDFium's copy of check_op.h

Having used these previously non-existent forms in an unrelated CL,
and consequently having it fail to compile, was an irritation to
be avoided.

-- use it in a few places.
-- remove one redundant check and some blank lines.

Bug: pdfium:1636
Change-Id: Ie0a24e7379fd29018ec558c6ec8aaab349230299
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/81730
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.cpp b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
index 889088b..e46013f 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
@@ -27,6 +27,7 @@
 #include "core/fxcrt/fx_extension.h"
 #include "core/fxcrt/fx_safe_types.h"
 #include "third_party/base/check.h"
+#include "third_party/base/check_op.h"
 #include "third_party/base/numerics/safe_math.h"
 
 namespace {
@@ -768,7 +769,7 @@
       return nullptr;
 
     len = streamEndPos - streamStartPos;
-    DCHECK(len >= 0);
+    DCHECK_GE(len, 0);
     if (len > 0) {
       SetPos(streamStartPos);
       // Check data availability first to allow the Validator to request data
@@ -887,7 +888,7 @@
 FX_FILESIZE CPDF_SyntaxParser::FindTag(ByteStringView tag) {
   const FX_FILESIZE startpos = GetPos();
   const int32_t taglen = tag.GetLength();
-  DCHECK(taglen > 0);
+  DCHECK_GT(taglen, 0);
 
   int32_t match = 0;
   while (1) {
diff --git a/core/fxcodec/progressive_decoder.cpp b/core/fxcodec/progressive_decoder.cpp
index 91a36f9..f797a4c 100644
--- a/core/fxcodec/progressive_decoder.cpp
+++ b/core/fxcodec/progressive_decoder.cpp
@@ -20,6 +20,7 @@
 #include "core/fxge/dib/cfx_dibitmap.h"
 #include "core/fxge/dib/fx_dib.h"
 #include "third_party/base/check.h"
+#include "third_party/base/check_op.h"
 #include "third_party/base/notreached.h"
 
 #ifdef PDF_ENABLE_XFA_BMP
@@ -68,7 +69,7 @@
 ProgressiveDecoder::WeightTable::~WeightTable() = default;
 
 void ProgressiveDecoder::WeightTable::Calc(int dest_len, int src_len) {
-  CHECK(dest_len >= 0);
+  CHECK_GE(dest_len, 0);
   double scale = static_cast<double>(src_len) / dest_len;
   m_ItemSize = (int)(sizeof(int) * 2 + sizeof(int) * (ceil(fabs(scale)) + 1));
   m_DestMin = 0;
@@ -142,7 +143,7 @@
 ProgressiveDecoder::HorzTable::~HorzTable() = default;
 
 void ProgressiveDecoder::HorzTable::Calc(int dest_len, int src_len) {
-  CHECK(dest_len >= 0);
+  CHECK_GE(dest_len, 0);
   double scale = (double)dest_len / (double)src_len;
   m_ItemSize = sizeof(int) * 4;
   int size = dest_len * m_ItemSize + 4;
@@ -196,7 +197,7 @@
 ProgressiveDecoder::VertTable::~VertTable() = default;
 
 void ProgressiveDecoder::VertTable::Calc(int dest_len, int src_len) {
-  CHECK(dest_len >= 0);
+  CHECK_GE(dest_len, 0);
   double scale = (double)dest_len / (double)src_len;
   m_ItemSize = sizeof(int) * 4;
   int size = dest_len * m_ItemSize + 4;
diff --git a/core/fxcrt/cfx_seekablestreamproxy.cpp b/core/fxcrt/cfx_seekablestreamproxy.cpp
index d14b7f2..78c2e1a 100644
--- a/core/fxcrt/cfx_seekablestreamproxy.cpp
+++ b/core/fxcrt/cfx_seekablestreamproxy.cpp
@@ -17,6 +17,7 @@
 #include "core/fxcrt/fx_memory_wrappers.h"
 #include "core/fxcrt/fx_safe_types.h"
 #include "third_party/base/check.h"
+#include "third_party/base/check_op.h"
 #include "third_party/base/stl_util.h"
 
 namespace {
@@ -72,7 +73,7 @@
 
 void UTF16ToWChar(void* pBuffer, size_t iLength) {
   DCHECK(pBuffer);
-  DCHECK(iLength > 0);
+  DCHECK_GT(iLength, 0);
 
   uint16_t* pSrc = static_cast<uint16_t*>(pBuffer);
   wchar_t* pDst = static_cast<wchar_t*>(pBuffer);
diff --git a/core/fxcrt/css/cfx_cssdeclaration.cpp b/core/fxcrt/css/cfx_cssdeclaration.cpp
index 823659d..9319f59 100644
--- a/core/fxcrt/css/cfx_cssdeclaration.cpp
+++ b/core/fxcrt/css/cfx_cssdeclaration.cpp
@@ -20,6 +20,7 @@
 #include "core/fxcrt/fx_extension.h"
 #include "core/fxcrt/fx_system.h"
 #include "third_party/base/check.h"
+#include "third_party/base/check_op.h"
 #include "third_party/base/notreached.h"
 
 namespace {
@@ -33,7 +34,7 @@
                     float* pValue,
                     CFX_CSSNumberValue::Unit* pOutUnit) {
   DCHECK(pszValue);
-  DCHECK(iValueLen > 0);
+  DCHECK_GT(iValueLen, 0);
 
   int32_t iUsedLen = 0;
   *pValue = FXSYS_wcstof(pszValue, iValueLen, &iUsedLen);
@@ -62,7 +63,7 @@
                                         int32_t* iOffset,
                                         int32_t* iLength) {
   DCHECK(pszValue);
-  DCHECK(iValueLen > 0);
+  DCHECK_GT(iValueLen, 0);
 
   *iOffset = 0;
   *iLength = iValueLen;
@@ -80,8 +81,7 @@
 bool CFX_CSSDeclaration::ParseCSSColor(const wchar_t* pszValue,
                                        int32_t iValueLen,
                                        FX_ARGB* dwColor) {
-  DCHECK(pszValue);
-  DCHECK(iValueLen > 0);
+  DCHECK_GT(iValueLen, 0);
   DCHECK(dwColor);
 
   if (*pszValue == '#') {
diff --git a/core/fxcrt/css/cfx_cssvaluelistparser.cpp b/core/fxcrt/css/cfx_cssvaluelistparser.cpp
index af6aa3c..67d83dde6 100644
--- a/core/fxcrt/css/cfx_cssvaluelistparser.cpp
+++ b/core/fxcrt/css/cfx_cssvaluelistparser.cpp
@@ -8,13 +8,14 @@
 
 #include "core/fxcrt/fx_extension.h"
 #include "third_party/base/check.h"
+#include "third_party/base/check_op.h"
 
 CFX_CSSValueListParser::CFX_CSSValueListParser(const wchar_t* psz,
                                                int32_t iLen,
                                                wchar_t separator)
     : m_Separator(separator), m_pCur(psz), m_pEnd(psz + iLen) {
   DCHECK(psz);
-  DCHECK(iLen > 0);
+  DCHECK_GT(iLen, 0);
 }
 
 bool CFX_CSSValueListParser::NextValue(CFX_CSSValue::PrimitiveType* eType,
diff --git a/core/fxcrt/string_data_template.cpp b/core/fxcrt/string_data_template.cpp
index ad87af6..b6356a8 100644
--- a/core/fxcrt/string_data_template.cpp
+++ b/core/fxcrt/string_data_template.cpp
@@ -10,6 +10,7 @@
 #include "core/fxcrt/fx_safe_types.h"
 #include "third_party/base/allocator/partition_allocator/partition_alloc.h"
 #include "third_party/base/check.h"
+#include "third_party/base/check_op.h"
 
 namespace fxcrt {
 
@@ -17,7 +18,7 @@
 template <typename CharType>
 StringDataTemplate<CharType>* StringDataTemplate<CharType>::Create(
     size_t nLen) {
-  DCHECK(nLen > 0);
+  DCHECK_GT(nLen, 0);
 
   // Calculate space needed for the fixed portion of the struct plus the
   // NUL char that is not included in |m_nAllocLength|.
@@ -68,9 +69,8 @@
 template <typename CharType>
 void StringDataTemplate<CharType>::CopyContents(const CharType* pStr,
                                                 size_t nLen) {
-  DCHECK(nLen >= 0);
-  DCHECK(nLen <= m_nAllocLength);
-
+  DCHECK_GE(nLen, 0);
+  DCHECK_LE(nLen, m_nAllocLength);
   memcpy(m_String, pStr, nLen * sizeof(CharType));
   m_String[nLen] = 0;
 }
@@ -79,10 +79,9 @@
 void StringDataTemplate<CharType>::CopyContentsAt(size_t offset,
                                                   const CharType* pStr,
                                                   size_t nLen) {
-  DCHECK(offset >= 0);
-  DCHECK(nLen >= 0);
-  DCHECK(offset + nLen <= m_nAllocLength);
-
+  DCHECK_GE(offset, 0);
+  DCHECK_GE(nLen, 0);
+  DCHECK_LE(offset + nLen, m_nAllocLength);
   memcpy(m_String + offset, pStr, nLen * sizeof(CharType));
   m_String[offset + nLen] = 0;
 }
@@ -91,8 +90,8 @@
 StringDataTemplate<CharType>::StringDataTemplate(size_t dataLen,
                                                  size_t allocLen)
     : m_nDataLength(dataLen), m_nAllocLength(allocLen) {
-  DCHECK(dataLen >= 0);
-  DCHECK(dataLen <= allocLen);
+  DCHECK_GE(dataLen, 0);
+  DCHECK_LE(dataLen, allocLen);
   m_String[dataLen] = 0;
 }
 
diff --git a/third_party/base/check_op.h b/third_party/base/check_op.h
index ef732ab..4722421 100644
--- a/third_party/base/check_op.h
+++ b/third_party/base/check_op.h
@@ -9,7 +9,16 @@
 
 #define CHECK_EQ(x, y) CHECK((x) == (y))
 #define CHECK_NE(x, y) CHECK((x) != (y))
+#define CHECK_LT(x, y) CHECK((x) < (y))
+#define CHECK_GT(x, y) CHECK((x) > (y))
+#define CHECK_LE(x, y) CHECK((x) <= (y))
+#define CHECK_GE(x, y) CHECK((x) >= (y))
+
 #define DCHECK_EQ(x, y) DCHECK((x) == (y))
 #define DCHECK_NE(x, y) DCHECK((x) != (y))
+#define DCHECK_LT(x, y) DCHECK((x) < (y))
+#define DCHECK_GT(x, y) DCHECK((x) > (y))
+#define DCHECK_LE(x, y) DCHECK((x) <= (y))
+#define DCHECK_GE(x, y) DCHECK((x) >= (y))
 
 #endif  // THIRD_PARTY_BASE_CHECK_OP_H_