Convert 2-dimensional C-style arrays to std::array<>.

-- fix one other obvious UNSAFE_TODO() encountered along the way.

Bug: 42271176
Change-Id: Ia6a9044ac34e42fb3dbbaff3406b9888772a4a66
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/120450
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Thomas Sepez <tsepez@google.com>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/parser/cpdf_object_unittest.cpp b/core/fpdfapi/parser/cpdf_object_unittest.cpp
index f788e64..577593b 100644
--- a/core/fpdfapi/parser/cpdf_object_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_object_unittest.cpp
@@ -25,6 +25,7 @@
 #include "core/fpdfapi/parser/cpdf_string.h"
 #include "core/fxcrt/compiler_specific.h"
 #include "core/fxcrt/data_vector.h"
+#include "core/fxcrt/stl_util.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 namespace {
@@ -95,9 +96,9 @@
         CPDF_Object::kNumber,  CPDF_Object::kString,  CPDF_Object::kString,
         CPDF_Object::kName,    CPDF_Object::kArray,   CPDF_Object::kDictionary,
         CPDF_Object::kStream,  CPDF_Object::kNullobj};
-    for (size_t i = 0; i < std::size(objs); ++i)
-      m_DirectObjs.emplace_back(UNSAFE_TODO(objs[i]));
-
+    for (auto* obj : objs) {
+      m_DirectObjs.emplace_back(obj);
+    }
     // Indirect references to indirect objects.
     m_ObjHolder = std::make_unique<CPDF_IndirectObjectHolder>();
     m_IndirectObjNums = {
@@ -451,45 +452,40 @@
 }
 
 TEST(PDFArrayTest, GetMatrix) {
-  float elems[][6] = {{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f},
-                      {1, 2, 3, 4, 5, 6},
-                      {2.3f, 4.05f, 3, -2, -3, 0.0f},
-                      {0.05f, 0.1f, 0.56f, 0.67f, 1.34f, 99.9f}};
-  for (size_t i = 0; i < std::size(elems); ++i) {
+  using Row = std::array<float, 6>;
+  constexpr auto elems = fxcrt::ToArray<const Row>({
+      {{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}},
+      {{1, 2, 3, 4, 5, 6}},
+      {{2.3f, 4.05f, 3, -2, -3, 0.0f}},
+      {{0.05f, 0.1f, 0.56f, 0.67f, 1.34f, 99.9f}},
+  });
+  for (const auto& elem : elems) {
     auto arr = pdfium::MakeRetain<CPDF_Array>();
-    CFX_Matrix matrix(UNSAFE_TODO(elems[i][0]), UNSAFE_TODO(elems[i][1]),
-                      UNSAFE_TODO(elems[i][2]), UNSAFE_TODO(elems[i][3]),
-                      UNSAFE_TODO(elems[i][4]), UNSAFE_TODO(elems[i][5]));
-    for (size_t j = 0; j < 6; ++j) {
-      arr->AppendNew<CPDF_Number>(UNSAFE_TODO(elems[i][j]));
+    for (float f : elem) {
+      arr->AppendNew<CPDF_Number>(f);
     }
+    CFX_Matrix matrix(elem[0], elem[1], elem[2], elem[3], elem[4], elem[5]);
     CFX_Matrix arr_matrix = arr->GetMatrix();
-    EXPECT_EQ(matrix.a, arr_matrix.a);
-    EXPECT_EQ(matrix.b, arr_matrix.b);
-    EXPECT_EQ(matrix.c, arr_matrix.c);
-    EXPECT_EQ(matrix.d, arr_matrix.d);
-    EXPECT_EQ(matrix.e, arr_matrix.e);
-    EXPECT_EQ(matrix.f, arr_matrix.f);
+    EXPECT_EQ(matrix, arr_matrix);
   }
 }
 
 TEST(PDFArrayTest, GetRect) {
-  float elems[][4] = {{0.0f, 0.0f, 0.0f, 0.0f},
-                      {1, 2, 5, 6},
-                      {2.3f, 4.05f, -3, 0.0f},
-                      {0.05f, 0.1f, 1.34f, 99.9f}};
-  for (size_t i = 0; i < std::size(elems); ++i) {
+  using Row = std::array<float, 4>;
+  constexpr auto elems = fxcrt::ToArray<const Row>({
+      {{0.0f, 0.0f, 0.0f, 0.0f}},
+      {{1, 2, 5, 6}},
+      {{2.3f, 4.05f, -3, 0.0f}},
+      {{0.05f, 0.1f, 1.34f, 99.9f}},
+  });
+  for (const auto& elem : elems) {
     auto arr = pdfium::MakeRetain<CPDF_Array>();
-    CFX_FloatRect rect(UNSAFE_TODO(elems[i][0]), UNSAFE_TODO(elems[i][1]),
-                       UNSAFE_TODO(elems[i][2]), UNSAFE_TODO(elems[i][3]));
-    for (size_t j = 0; j < 4; ++j) {
-      arr->AppendNew<CPDF_Number>(UNSAFE_TODO(elems[i][j]));
+    for (float f : elem) {
+      arr->AppendNew<CPDF_Number>(f);
     }
+    CFX_FloatRect rect(elem[0], elem[1], elem[2], elem[3]);
     CFX_FloatRect arr_rect = arr->GetRect();
-    EXPECT_EQ(rect.left, arr_rect.left);
-    EXPECT_EQ(rect.right, arr_rect.right);
-    EXPECT_EQ(rect.bottom, arr_rect.bottom);
-    EXPECT_EQ(rect.top, arr_rect.top);
+    EXPECT_EQ(rect, arr_rect);
   }
 }
 
diff --git a/xfa/fgas/font/cfgas_pdffontmgr.cpp b/xfa/fgas/font/cfgas_pdffontmgr.cpp
index 668591b..01a32f2 100644
--- a/xfa/fgas/font/cfgas_pdffontmgr.cpp
+++ b/xfa/fgas/font/cfgas_pdffontmgr.cpp
@@ -7,6 +7,7 @@
 #include "xfa/fgas/font/cfgas_pdffontmgr.h"
 
 #include <algorithm>
+#include <array>
 #include <iterator>
 #include <utility>
 
@@ -16,7 +17,7 @@
 #include "core/fpdfapi/parser/cpdf_document.h"
 #include "core/fpdfapi/parser/fpdf_parser_utility.h"
 #include "core/fxcrt/check.h"
-#include "core/fxcrt/compiler_specific.h"
+#include "core/fxcrt/stl_util.h"
 #include "core/fxge/fx_font.h"
 #include "xfa/fgas/font/cfgas_fontmgr.h"
 #include "xfa/fgas/font/cfgas_gefont.h"
@@ -24,11 +25,12 @@
 namespace {
 
 // The 5 names per entry are: PsName, Normal, Bold, Italic, BoldItalic.
-const char* const kXFAPDFFontName[][5] = {
-    {"Adobe PI Std", "AdobePIStd", "AdobePIStd", "AdobePIStd", "AdobePIStd"},
-    {"Myriad Pro Light", "MyriadPro-Light", "MyriadPro-Semibold",
-     "MyriadPro-LightIt", "MyriadPro-SemiboldIt"},
-};
+using FontNameEntry = std::array<const char*, 5>;
+constexpr auto kXFAPDFFontNameTable = fxcrt::ToArray<const FontNameEntry>({
+    {{"Adobe PI Std", "AdobePIStd", "AdobePIStd", "AdobePIStd", "AdobePIStd"}},
+    {{"Myriad Pro Light", "MyriadPro-Light", "MyriadPro-Semibold",
+      "MyriadPro-LightIt", "MyriadPro-SemiboldIt"}},
+});
 
 }  // namespace
 
@@ -102,14 +104,16 @@
 ByteString CFGAS_PDFFontMgr::PsNameToFontName(const ByteString& strPsName,
                                               bool bBold,
                                               bool bItalic) {
-  for (size_t i = 0; i < std::size(kXFAPDFFontName); ++i) {
-    if (strPsName == UNSAFE_TODO(kXFAPDFFontName[i][0])) {
+  for (const auto& entry : kXFAPDFFontNameTable) {
+    if (strPsName == entry[0]) {
       size_t index = 1;
-      if (bBold)
+      if (bBold) {
         ++index;
-      if (bItalic)
+      }
+      if (bItalic) {
         index += 2;
-      return UNSAFE_TODO(kXFAPDFFontName[i][index]);
+      }
+      return entry[index];
     }
   }
   return strPsName;