Fix shadowed variables

This CL fixes instances of variable shadowing that are
discovered by turning on -Wshadow.

BUG=pdfium:1137

Change-Id: I418d50de89ecbeb12e85b23a358bc61e8f16e888
Reviewed-on: https://pdfium-review.googlesource.com/41150
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.cpp b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
index 3acad52..89bf991 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
@@ -477,22 +477,22 @@
     std::unique_ptr<CPDF_Dictionary> pDict =
         pdfium::MakeUnique<CPDF_Dictionary>(m_pPool);
     while (1) {
-      ByteString word = GetNextWord(nullptr);
-      if (word.IsEmpty())
+      ByteString inner_word = GetNextWord(nullptr);
+      if (inner_word.IsEmpty())
         return nullptr;
 
-      FX_FILESIZE SavedPos = m_Pos - word.GetLength();
-      if (word == ">>")
+      FX_FILESIZE SavedPos = m_Pos - inner_word.GetLength();
+      if (inner_word == ">>")
         break;
 
-      if (word == "endobj") {
+      if (inner_word == "endobj") {
         m_Pos = SavedPos;
         break;
       }
-      if (word[0] != '/')
+      if (inner_word[0] != '/')
         continue;
 
-      ByteString key = PDF_NameDecode(word.AsStringView());
+      ByteString key = PDF_NameDecode(inner_word.AsStringView());
       if (key.IsEmpty() && parse_type == ParseType::kLoose)
         continue;
 
diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp
index 2353317..8375d1f 100644
--- a/core/fpdftext/cpdf_textpage.cpp
+++ b/core/fpdftext/cpdf_textpage.cpp
@@ -494,11 +494,11 @@
   if (FPDFTEXT_CHAR_PIECE == charinfo2.m_Flag) {
     PAGECHAR_INFO charinfo3 = charinfo2;
     int endIndex = start + nCount - 1;
-    const int nCount = CountChars();
+    const int innerCount = CountChars();
     while (FPDFTEXT_CHAR_PIECE == charinfo3.m_Flag &&
            charinfo3.m_Index == charinfo2.m_Index) {
       endIndex++;
-      if (endIndex >= nCount)
+      if (endIndex >= innerCount)
         break;
       charinfo3 = m_CharList[endIndex];
     }
@@ -1316,8 +1316,8 @@
           if (re.Contains(pObj->GetPos())) {
             bNewline = false;
           } else {
-            CFX_FloatRect rect(0, pObj->m_Bottom, 1000, pObj->m_Top);
-            if (rect.Contains(m_pPreTextObj->GetPos()))
+            if (CFX_FloatRect(0, pObj->m_Bottom, 1000, pObj->m_Top)
+                    .Contains(m_pPreTextObj->GetPos()))
               bNewline = false;
           }
         }
diff --git a/core/fxcodec/bmp/cfx_bmpdecompressor.cpp b/core/fxcodec/bmp/cfx_bmpdecompressor.cpp
index 739853a..3839556 100644
--- a/core/fxcodec/bmp/cfx_bmpdecompressor.cpp
+++ b/core/fxcodec/bmp/cfx_bmpdecompressor.cpp
@@ -65,9 +65,9 @@
   longjmp(jmpbuf_, 1);
 }
 
-void CFX_BmpDecompressor::ReadScanline(uint32_t row_num_,
+void CFX_BmpDecompressor::ReadScanline(uint32_t row_num,
                                        const std::vector<uint8_t>& row_buf) {
-  context_ptr_->m_pDelegate->BmpReadScanline(row_num_, row_buf);
+  context_ptr_->m_pDelegate->BmpReadScanline(row_num, row_buf);
 }
 
 bool CFX_BmpDecompressor::GetDataPosition(uint32_t rcd_pos) {
diff --git a/core/fxge/android/cfpf_skiafontmgr.cpp b/core/fxge/android/cfpf_skiafontmgr.cpp
index f9afdab..2288a86 100644
--- a/core/fxge/android/cfpf_skiafontmgr.cpp
+++ b/core/fxge/android/cfpf_skiafontmgr.cpp
@@ -252,9 +252,9 @@
                                             uint8_t uCharset,
                                             uint32_t dwStyle) {
   uint32_t dwHash = FPF_SKIAGetFamilyHash(bsFamilyname, dwStyle, uCharset);
-  auto it = m_FamilyFonts.find(dwHash);
-  if (it != m_FamilyFonts.end())
-    return it->second.get();
+  auto family_iter = m_FamilyFonts.find(dwHash);
+  if (family_iter != m_FamilyFonts.end())
+    return family_iter->second.get();
 
   uint32_t dwFaceName = FPF_SKIANormalizeFontName(bsFamilyname);
   uint32_t dwSubst = FPF_SkiaGetSubstFont(dwFaceName, g_SkiaFontmap,
@@ -273,8 +273,9 @@
   const CFPF_SkiaPathFont* pBestFont = nullptr;
   int32_t nMax = -1;
   int32_t nGlyphNum = 0;
-  for (auto it = m_FontFaces.rbegin(); it != m_FontFaces.rend(); ++it) {
-    const CFPF_SkiaPathFont* pFont = it->get();
+  for (auto face_iter = m_FontFaces.rbegin(); face_iter != m_FontFaces.rend();
+       ++face_iter) {
+    const CFPF_SkiaPathFont* pFont = face_iter->get();
     if (!(pFont->charsets() & FPF_SkiaGetCharset(uCharset)))
       continue;
     int32_t nFind = 0;
@@ -301,19 +302,19 @@
     if (uCharset == FX_CHARSET_Default || bMaybeSymbol) {
       if (nFind > nMax && bMatchedName) {
         nMax = nFind;
-        pBestFont = it->get();
+        pBestFont = face_iter->get();
       }
     } else if (FPF_SkiaIsCJK(uCharset)) {
       if (bMatchedName || pFont->glyph_num() > nGlyphNum) {
-        pBestFont = it->get();
+        pBestFont = face_iter->get();
         nGlyphNum = pFont->glyph_num();
       }
     } else if (nFind > nMax) {
       nMax = nFind;
-      pBestFont = it->get();
+      pBestFont = face_iter->get();
     }
     if (nExpectVal <= nFind) {
-      pBestFont = it->get();
+      pBestFont = face_iter->get();
       break;
     }
   }
diff --git a/core/fxge/cfx_fontmapper.cpp b/core/fxge/cfx_fontmapper.cpp
index c7a7015..461094d 100644
--- a/core/fxge/cfx_fontmapper.cpp
+++ b/core/fxge/cfx_fontmapper.cpp
@@ -149,6 +149,14 @@
     {"ForteMT", "Forte"},
 };
 
+#if _FX_PLATFORM_ == _FX_PLATFORM_LINUX_
+const char kNarrowFamily[] = "LiberationSansNarrow";
+#elif _FX_PLATFORM_ == _FX_PLATFORM_ANDROID_
+const char kNarrowFamily[] = "RobotoCondensed";
+#else
+const char kNarrowFamily[] = "ArialNarrow";
+#endif  // _FX_PLATFORM_ == _FX_PLATFORM_LINUX_
+
 ByteString TT_NormalizeName(const char* family) {
   ByteString norm(family);
   norm.Remove(' ');
@@ -415,14 +423,16 @@
   ByteString style;
   bool bHasComma = false;
   bool bHasHyphen = false;
-  auto pos = SubstName.Find(",", 0);
-  if (pos.has_value()) {
-    family = SubstName.Left(pos.value());
-    PDF_GetStandardFontName(&family);
-    style = SubstName.Right(SubstName.GetLength() - (pos.value() + 1));
-    bHasComma = true;
-  } else {
-    family = SubstName;
+  {
+    Optional<size_t> pos = SubstName.Find(",", 0);
+    if (pos.has_value()) {
+      family = SubstName.Left(pos.value());
+      PDF_GetStandardFontName(&family);
+      style = SubstName.Right(SubstName.GetLength() - (pos.value() + 1));
+      bHasComma = true;
+    } else {
+      family = SubstName;
+    }
   }
   for (; iBaseFont < 12; iBaseFont++) {
     if (family == ByteStringView(g_Base14FontNames[iBaseFont]))
@@ -443,7 +453,7 @@
   } else {
     iBaseFont = kNumStandardFonts;
     if (!bHasComma) {
-      pos = family.ReverseFind('-');
+      Optional<size_t> pos = family.ReverseFind('-');
       if (pos.has_value()) {
         style = family.Right(family.GetLength() - (pos.value() + 1));
         family = family.Left(pos.value());
@@ -540,19 +550,12 @@
         bItalic = italic_angle != 0;
         weight = old_weight;
       }
-#if _FX_PLATFORM_ == _FX_PLATFORM_LINUX_
-      const char* narrow_family = "LiberationSansNarrow";
-#elif _FX_PLATFORM_ == _FX_PLATFORM_ANDROID_
-      const char* narrow_family = "RobotoCondensed";
-#else
-      const char* narrow_family = "ArialNarrow";
-#endif  // _FX_PLATFORM_ == _FX_PLATFORM_LINUX_
-      auto pos = SubstName.Find("Narrow");
+      Optional<size_t> pos = SubstName.Find("Narrow");
       if (pos.has_value() && pos.value() != 0)
-        family = narrow_family;
+        family = kNarrowFamily;
       pos = SubstName.Find("Condensed");
       if (pos.has_value() && pos.value() != 0)
-        family = narrow_family;
+        family = kNarrowFamily;
     } else {
       pSubstFont->m_bSubstCJK = true;
       if (nStyle)
diff --git a/fpdfsdk/formfiller/cba_fontmap.cpp b/fpdfsdk/formfiller/cba_fontmap.cpp
index 98464cb..577f1e0 100644
--- a/fpdfsdk/formfiller/cba_fontmap.cpp
+++ b/fpdfsdk/formfiller/cba_fontmap.cpp
@@ -154,8 +154,7 @@
     pAPDict = m_pAnnotDict->SetNewFor<CPDF_Dictionary>("AP");
 
   // to avoid checkbox and radiobutton
-  CPDF_Object* pObject = pAPDict->GetObjectFor(m_sAPType);
-  if (ToDictionary(pObject))
+  if (ToDictionary(pAPDict->GetObjectFor(m_sAPType)))
     return;
 
   CPDF_Stream* pStream = pAPDict->GetStreamFor(m_sAPType);
diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp
index d20b28f..2458e93 100644
--- a/fpdfsdk/fpdf_transformpage.cpp
+++ b/fpdfsdk/fpdf_transformpage.cpp
@@ -147,7 +147,7 @@
     pContentArray->InsertAt(0, pStream->MakeReference(pDoc));
     pContentArray->Add(pEndStream->MakeReference(pDoc));
   } else if (pContentObj->IsStream() && !pContentObj->IsInline()) {
-    CPDF_Array* pContentArray = pDoc->NewIndirect<CPDF_Array>();
+    pContentArray = pDoc->NewIndirect<CPDF_Array>();
     pContentArray->Add(pStream->MakeReference(pDoc));
     pContentArray->Add(pContentObj->MakeReference(pDoc));
     pContentArray->Add(pEndStream->MakeReference(pDoc));
diff --git a/fxjs/cfxjs_engine_embeddertest.cpp b/fxjs/cfxjs_engine_embeddertest.cpp
index ff866d3..a9422ec 100644
--- a/fxjs/cfxjs_engine_embeddertest.cpp
+++ b/fxjs/cfxjs_engine_embeddertest.cpp
@@ -51,10 +51,12 @@
   engine2.InitializeEngine();
 
   v8::Context::Scope context_scope(GetV8Context());
-  Optional<IJS_Runtime::JS_Error> err = engine()->Execute(WideString(kScript0));
-  EXPECT_FALSE(err);
-  CheckAssignmentInEngineContext(engine(), kExpected0);
-
+  {
+    Optional<IJS_Runtime::JS_Error> err =
+        engine()->Execute(WideString(kScript0));
+    EXPECT_FALSE(err);
+    CheckAssignmentInEngineContext(engine(), kExpected0);
+  }
   {
     // engine1 executing in engine1's context doesn't affect main.
     v8::Context::Scope context_scope1(engine1.GetV8Context());
diff --git a/fxjs/cfxjse_engine.cpp b/fxjs/cfxjse_engine.cpp
index 3b60989..c3b9dd3 100644
--- a/fxjs/cfxjse_engine.cpp
+++ b/fxjs/cfxjse_engine.cpp
@@ -334,7 +334,6 @@
                                                szPropName, pReturnValue, true);
 
     if (!bRet) {
-      WideString wsPropName = WideString::FromUTF8(szPropName);
       const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo =
           XFA_GetScriptAttributeByName(pObject->GetElementType(),
                                        wsPropName.AsStringView());
diff --git a/fxjs/cfxjse_formcalc_context.cpp b/fxjs/cfxjse_formcalc_context.cpp
index 34f5642..41ec578 100644
--- a/fxjs/cfxjse_formcalc_context.cpp
+++ b/fxjs/cfxjse_formcalc_context.cpp
@@ -780,11 +780,11 @@
 
     ++iIndex;
     char strSec[kSubSecondLength + 1];
-    for (int i = 0; i < kSubSecondLength; ++i) {
-      char c = pData[iIndex + i];
+    for (int j = 0; j < kSubSecondLength; ++j) {
+      char c = pData[iIndex + j];
       if (!std::isdigit(c))
         return false;
-      strSec[i] = c;
+      strSec[j] = c;
     }
     strSec[kSubSecondLength] = '\0';
 
diff --git a/fxjs/xfa/cjx_tree.cpp b/fxjs/xfa/cjx_tree.cpp
index 23f7658..5921f8b 100644
--- a/fxjs/xfa/cjx_tree.cpp
+++ b/fxjs/xfa/cjx_tree.cpp
@@ -239,13 +239,13 @@
     if (resolveNodeRS.pScriptAttribute &&
         resolveNodeRS.pScriptAttribute->eValueType == XFA_ScriptType::Object) {
       for (auto& pObject : resolveNodeRS.objects) {
-        auto pValue =
+        auto innerValue =
             pdfium::MakeUnique<CFXJSE_Value>(pScriptContext->GetIsolate());
         CJX_Object* jsObject = pObject->JSObject();
         (jsObject->*(resolveNodeRS.pScriptAttribute->callback))(
-            pValue.get(), false, resolveNodeRS.pScriptAttribute->attribute);
+            innerValue.get(), false, resolveNodeRS.pScriptAttribute->attribute);
 
-        CXFA_Object* obj = CFXJSE_Engine::ToObject(pValue.get());
+        CXFA_Object* obj = CFXJSE_Engine::ToObject(innerValue.get());
         if (obj->IsNode())
           pNodeList->Append(obj->AsNode());
       }
diff --git a/xfa/fxfa/cxfa_ffdocview.cpp b/xfa/fxfa/cxfa_ffdocview.cpp
index affdca2..e4beae4 100644
--- a/xfa/fxfa/cxfa_ffdocview.cpp
+++ b/xfa/fxfa/cxfa_ffdocview.cpp
@@ -235,9 +235,9 @@
   if (pFormNode->GetElementType() != XFA_Element::Field &&
       pFormNode->GetElementType() != XFA_Element::ExclGroup) {
     CXFA_ReadyNodeIterator it(pFormNode);
-    while (CXFA_Node* pNode = it.MoveToNext()) {
-      bChanged |= ResetSingleNodeData(pNode);
-      if (pNode->GetElementType() == XFA_Element::ExclGroup)
+    while (CXFA_Node* next_node = it.MoveToNext()) {
+      bChanged |= ResetSingleNodeData(next_node);
+      if (next_node->GetElementType() == XFA_Element::ExclGroup)
         it.SkipTree();
     }
   }
diff --git a/xfa/fxfa/parser/cxfa_document_parser.cpp b/xfa/fxfa/parser/cxfa_document_parser.cpp
index d0f137d..7fd4ff1 100644
--- a/xfa/fxfa/parser/cxfa_document_parser.cpp
+++ b/xfa/fxfa/parser/cxfa_document_parser.cpp
@@ -447,8 +447,7 @@
   m_pRootNode = pXFARootNode;
   pXFARootNode->JSObject()->SetCData(XFA_Attribute::Name, L"xfa", false, false);
 
-  CFX_XMLElement* pElement = ToXMLElement(pXMLDocumentNode);
-  for (auto it : pElement->GetAttributes()) {
+  for (auto it : ToXMLElement(pXMLDocumentNode)->GetAttributes()) {
     if (it.first == L"uuid")
       pXFARootNode->JSObject()->SetCData(XFA_Attribute::Uuid, it.second, false,
                                          false);
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index c41a1ac..7e582c0 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -3985,10 +3985,10 @@
 
   int32_t iSel = -1;
   std::vector<WideString> wsValueArray = GetSelectedItemsValue();
-  auto it = std::find(wsValueArray.begin(), wsValueArray.end(),
-                      wsSaveTextArray[nIndex]);
-  if (it != wsValueArray.end())
-    iSel = it - wsValueArray.begin();
+  auto value_iter = std::find(wsValueArray.begin(), wsValueArray.end(),
+                              wsSaveTextArray[nIndex]);
+  if (value_iter != wsValueArray.end())
+    iSel = value_iter - wsValueArray.begin();
 
   if (IsChoiceListMultiSelect()) {
     if (bSelected) {
@@ -4003,9 +4003,10 @@
       }
     } else if (iSel >= 0) {
       std::vector<int32_t> iSelArray = GetSelectedItems();
-      auto it = std::find(iSelArray.begin(), iSelArray.end(), nIndex);
-      if (it != iSelArray.end())
-        iSelArray.erase(it);
+      auto selected_iter =
+          std::find(iSelArray.begin(), iSelArray.end(), nIndex);
+      if (selected_iter != iSelArray.end())
+        iSelArray.erase(selected_iter);
       SetSelectedItems(iSelArray, bNotify, bScriptModify, bSyncData);
     }
   } else {