Fix more size_t length calculations in fxjs/

Change-Id: I83d891e5bc6ed31201b1a0a0b35e93f303d6b72b
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/87051
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp
index fa93ed3..a13b95d 100644
--- a/fxjs/cjs_publicmethods.cpp
+++ b/fxjs/cjs_publicmethods.cpp
@@ -36,6 +36,7 @@
 #include "third_party/abseil-cpp/absl/types/optional.h"
 #include "third_party/base/check.h"
 #include "third_party/base/cxx17_backports.h"
+#include "third_party/base/numerics/safe_conversions.h"
 #include "v8/include/v8-container.h"
 
 // static
@@ -121,7 +122,8 @@
   ss << std::fixed << std::setprecision(iDec) << dValue;
   std::string value = ss.str();
   size_t pos = value.find('.');
-  *iDec2 = pos == std::string::npos ? value.size() : static_cast<int>(pos);
+  *iDec2 = pdfium::base::checked_cast<int>(
+      pos == std::string::npos ? value.size() : pos);
   return ByteString(value.c_str());
 }
 #endif
@@ -932,7 +934,7 @@
   sTemp = wsArray[1];
   for (size_t i = 0; i < pdfium::size(fxjs::kMonths); ++i) {
     if (sTemp == fxjs::kMonths[i]) {
-      nMonth = i + 1;
+      nMonth = static_cast<int>(i) + 1;
       break;
     }
   }
diff --git a/fxjs/fx_date_helpers.cpp b/fxjs/fx_date_helpers.cpp
index c1d27e4..f722be0 100644
--- a/fxjs/fx_date_helpers.cpp
+++ b/fxjs/fx_date_helpers.cpp
@@ -116,7 +116,7 @@
       59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
   for (size_t i = 0; i < pdfium::size(kCumulativeDaysInMonths); ++i) {
     if (day < kCumulativeDaysInMonths[i])
-      return i + 1;
+      return static_cast<int>(i) + 1;
   }
 
   return -1;
@@ -436,7 +436,7 @@
                 WideString sMonth = value.Substr(j, KMonthAbbreviationLength);
                 for (size_t m = 0; m < pdfium::size(kMonths); ++m) {
                   if (sMonth.CompareNoCase(kMonths[m]) == 0) {
-                    nMonth = m + 1;
+                    nMonth = static_cast<int>(m) + 1;
                     i += 3;
                     j += nSkip;
                     bFind = true;
@@ -475,7 +475,7 @@
                   WideString sFullMonths = WideString(kFullMonths[m]);
                   sFullMonths.MakeLower();
                   if (sFullMonths.Contains(sMonth.AsStringView())) {
-                    nMonth = m + 1;
+                    nMonth = static_cast<int>(m) + 1;
                     i += 4;
                     j += nSkip;
                     bFind = true;
diff --git a/fxjs/xfa/cfxjse_resolveprocessor.cpp b/fxjs/xfa/cfxjse_resolveprocessor.cpp
index 243cb9e..566f955 100644
--- a/fxjs/xfa/cfxjse_resolveprocessor.cpp
+++ b/fxjs/xfa/cfxjse_resolveprocessor.cpp
@@ -156,8 +156,8 @@
                                             CFXJSE_ResolveNodeData& rnd) {
   WideString wsName = rnd.m_wsName;
   WideString wsCondition = rnd.m_wsCondition;
-  int32_t iNameLen = wsName.GetLength();
-  if (iNameLen == 1) {
+  size_t nNameLen = wsName.GetLength();
+  if (nNameLen == 1) {
     rnd.m_Result.objects.emplace_back(rnd.m_CurObject.Get());
     return true;
   }
@@ -165,7 +165,7 @@
     return false;
 
   XFA_HashCode dwNameHash = static_cast<XFA_HashCode>(
-      FX_HashCode_GetW(wsName.AsStringView().Last(iNameLen - 1)));
+      FX_HashCode_GetW(wsName.AsStringView().Last(nNameLen - 1)));
   if (dwNameHash == XFA_HASHCODE_Xfa) {
     rnd.m_Result.objects.emplace_back(rnd.m_pSC->GetDocument()->GetRoot());
   } else {
@@ -681,8 +681,8 @@
   size_t iFoundCount = pRnd->m_Result.objects.size();
   wsCondition.Trim();
 
-  int32_t iLen = wsCondition.GetLength();
-  if (!iLen) {
+  const size_t nLen = wsCondition.GetLength();
+  if (nLen == 0) {
     if (pRnd->m_dwStyles & XFA_ResolveFlag::kALL)
       return;
     if (iFoundCount == 1)
@@ -708,7 +708,7 @@
       ConditionArray(iCurIndex, wsCondition, iFoundCount, pRnd);
       return;
     case '.':
-      if (iLen > 1 && (wsCondition[1] == '[' || wsCondition[1] == '('))
+      if (nLen > 1 && (wsCondition[1] == '[' || wsCondition[1] == '('))
         DoPredicateFilter(pIsolate, wsCondition, iFoundCount, pRnd);
       return;
     case '(':
diff --git a/fxjs/xfa/cjx_eventpseudomodel.cpp b/fxjs/xfa/cjx_eventpseudomodel.cpp
index 21019cc..d77ce63 100644
--- a/fxjs/xfa/cjx_eventpseudomodel.cpp
+++ b/fxjs/xfa/cjx_eventpseudomodel.cpp
@@ -12,6 +12,7 @@
 #include "fxjs/fxv8.h"
 #include "fxjs/xfa/cfxjse_engine.h"
 #include "third_party/base/notreached.h"
+#include "third_party/base/numerics/safe_conversions.h"
 #include "v8/include/v8-primitive.h"
 #include "xfa/fxfa/cxfa_eventparam.h"
 #include "xfa/fxfa/cxfa_ffnotify.h"
@@ -286,18 +287,18 @@
       IntegerProperty(pIsolate, pValue, &pEventParam->m_iSelEnd, bSetting);
 
       pEventParam->m_iSelEnd = std::max(0, pEventParam->m_iSelEnd);
-      pEventParam->m_iSelEnd =
-          std::min(static_cast<size_t>(pEventParam->m_iSelEnd),
-                   pEventParam->m_wsPrevText.GetLength());
+      pEventParam->m_iSelEnd = std::min(
+          pEventParam->m_iSelEnd, pdfium::base::checked_cast<int32_t>(
+                                      pEventParam->m_wsPrevText.GetLength()));
       pEventParam->m_iSelStart =
           std::min(pEventParam->m_iSelStart, pEventParam->m_iSelEnd);
       break;
     case XFA_Event::SelectionStart:
       IntegerProperty(pIsolate, pValue, &pEventParam->m_iSelStart, bSetting);
       pEventParam->m_iSelStart = std::max(0, pEventParam->m_iSelStart);
-      pEventParam->m_iSelStart =
-          std::min(static_cast<size_t>(pEventParam->m_iSelStart),
-                   pEventParam->m_wsPrevText.GetLength());
+      pEventParam->m_iSelStart = std::min(
+          pEventParam->m_iSelStart, pdfium::base::checked_cast<int32_t>(
+                                        pEventParam->m_wsPrevText.GetLength()));
       pEventParam->m_iSelEnd =
           std::max(pEventParam->m_iSelStart, pEventParam->m_iSelEnd);
       break;