Convert FX_STRSIZE int->size_t

Change the underlying type for FX_STRSIZE to size_t from int. This
will make the value unsigned and thus all values in the range of the
type will be valid. This allows for the final remove of negative
length strings, but also introduces a some casting and functional 
errors, since many parts of the code base assume that FX_STRSIZE is 
int or another signed type. This also CL fixes these errors.

BUG=pdfium:828

Change-Id: I231dca59e96fc9330cbb099eecbdfc41fcf86f5b
Reviewed-on: https://pdfium-review.googlesource.com/11830
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
diff --git a/core/fxcrt/cfx_widestring.cpp b/core/fxcrt/cfx_widestring.cpp
index 05a4fc3..24b7fb5 100644
--- a/core/fxcrt/cfx_widestring.cpp
+++ b/core/fxcrt/cfx_widestring.cpp
@@ -293,10 +293,6 @@
 }
 
 CFX_WideString::CFX_WideString(const wchar_t* pStr, FX_STRSIZE nLen) {
-  ASSERT(nLen >= 0);
-  if (nLen < 0)
-    nLen = pStr ? FXSYS_wcslen(pStr) : 0;
-
   if (nLen)
     m_pData.Reset(StringData::Create(pStr, nLen));
 }
@@ -413,7 +409,7 @@
   if (!ptr)
     return m_pData->m_nDataLength == 0;
 
-  return wcslen(ptr) == static_cast<size_t>(m_pData->m_nDataLength) &&
+  return wcslen(ptr) == m_pData->m_nDataLength &&
          wmemcmp(ptr, m_pData->m_String, m_pData->m_nDataLength) == 0;
 }
 
@@ -481,7 +477,7 @@
   if (m_pData && m_pData->CanOperateInPlace(nNewLength))
     return;
 
-  if (nNewLength <= 0) {
+  if (nNewLength == 0) {
     clear();
     return;
   }
@@ -490,7 +486,6 @@
 }
 
 void CFX_WideString::ReleaseBuffer(FX_STRSIZE nNewLength) {
-  ASSERT(nNewLength >= 0);
   if (!m_pData)
     return;
 
@@ -545,7 +540,8 @@
     return 0;
 
   FX_STRSIZE old_length = m_pData->m_nDataLength;
-  if (count <= 0 || index != pdfium::clamp(index, 0, old_length))
+  if (count == 0 ||
+      index != pdfium::clamp(index, static_cast<FX_STRSIZE>(0), old_length))
     return old_length;
 
   FX_STRSIZE removal_length = index + count;
@@ -561,7 +557,7 @@
 }
 
 void CFX_WideString::Concat(const wchar_t* pSrcData, FX_STRSIZE nSrcLen) {
-  if (!pSrcData || nSrcLen <= 0)
+  if (!pSrcData || nSrcLen == 0)
     return;
 
   if (!m_pData) {
@@ -639,7 +635,7 @@
 void CFX_WideString::AllocCopy(CFX_WideString& dest,
                                FX_STRSIZE nCopyLen,
                                FX_STRSIZE nCopyIndex) const {
-  if (nCopyLen <= 0)
+  if (nCopyLen == 0)
     return;
 
   CFX_RetainPtr<StringData> pNewData(
@@ -676,7 +672,7 @@
     auto guess = GuessSizeForVSWPrintf(format, argListCopy);
     if (!guess.has_value())
       return;
-    maxLen = guess.value();
+    maxLen = pdfium::base::checked_cast<int>(guess.value());
   }
   while (maxLen < 32 * 1024) {
     FX_VA_COPY(argListCopy, argList);
@@ -864,7 +860,7 @@
 // static
 CFX_WideString CFX_WideString::FromUTF16LE(const unsigned short* wstr,
                                            FX_STRSIZE wlen) {
-  if (!wstr || wlen <= 0) {
+  if (!wstr || wlen == 0) {
     return CFX_WideString();
   }
 
@@ -963,7 +959,7 @@
     return;
 
   FX_STRSIZE len = GetLength();
-  if (len < 1)
+  if (len == 0)
     return;
 
   FX_STRSIZE pos = 0;
@@ -978,13 +974,14 @@
     }
     pos++;
   }
-  if (pos) {
-    ReallocBeforeWrite(len);
-    FX_STRSIZE nDataLength = len - pos;
-    memmove(m_pData->m_String, m_pData->m_String + pos,
-            (nDataLength + 1) * sizeof(wchar_t));
-    m_pData->m_nDataLength = nDataLength;
-  }
+  if (!pos)
+    return;
+
+  ReallocBeforeWrite(len);
+  FX_STRSIZE nDataLength = len - pos;
+  memmove(m_pData->m_String, m_pData->m_String + pos,
+          (nDataLength + 1) * sizeof(wchar_t));
+  m_pData->m_nDataLength = nDataLength;
 }
 
 void CFX_WideString::TrimLeft(wchar_t chTarget) {