Don't make the arraysize() macro cast to int.

Change-Id: I4c2d1d1d43b100ff5f6d1f58b03d5b0a1f22baa7
Reviewed-on: https://code-review.googlesource.com/c/re2/+/43030
Reviewed-by: Paul Wankadia <junyer@google.com>
diff --git a/re2/compile.cc b/re2/compile.cc
index ab18cef..7457b22 100644
--- a/re2/compile.cc
+++ b/re2/compile.cc
@@ -695,7 +695,7 @@
 
 void Compiler::Add_80_10ffff() {
   int inst[arraysize(prog_80_10ffff)] = { 0 }; // does not need to be initialized; silences gcc warning
-  for (int i = 0; i < arraysize(prog_80_10ffff); i++) {
+  for (size_t i = 0; i < arraysize(prog_80_10ffff); i++) {
     const ByteRangeProg& p = prog_80_10ffff[i];
     int next = 0;
     if (p.next >= 0)
diff --git a/re2/parse.cc b/re2/parse.cc
index f0a1387..93b922a 100644
--- a/re2/parse.cc
+++ b/re2/parse.cc
@@ -801,7 +801,7 @@
   // limit on the size of a concatenation, so we should never
   // see more than two here.
   Regexp* stk[4];
-  int d = 0;
+  size_t d = 0;
   while (re->op() == kRegexpConcat) {
     if (d < arraysize(stk))
       stk[d++] = re;
@@ -832,8 +832,8 @@
   }
 
   // If re is now empty, concatenations might simplify too.
-  while (d-- > 0) {
-    re = stk[d];
+  while (d > 0) {
+    re = stk[--d];
     Regexp** sub = re->sub();
     if (sub[0]->op() == kRegexpEmptyMatch) {
       sub[0]->Decref();
diff --git a/re2/re2.cc b/re2/re2.cc
index fe8eb34..50e2c49 100644
--- a/re2/re2.cc
+++ b/re2/re2.cc
@@ -368,7 +368,7 @@
                   const StringPiece& rewrite) {
   StringPiece vec[kVecSize];
   int nvec = 1 + MaxSubmatch(rewrite);
-  if (nvec > arraysize(vec))
+  if (nvec > static_cast<int>(arraysize(vec)))
     return false;
   if (!re.Match(*str, 0, str->size(), UNANCHORED, vec, nvec))
     return false;
@@ -388,7 +388,7 @@
                        const StringPiece& rewrite) {
   StringPiece vec[kVecSize];
   int nvec = 1 + MaxSubmatch(rewrite);
-  if (nvec > arraysize(vec))
+  if (nvec > static_cast<int>(arraysize(vec)))
     return false;
 
   const char* p = str->data();
@@ -460,7 +460,7 @@
                   std::string* out) {
   StringPiece vec[kVecSize];
   int nvec = 1 + MaxSubmatch(rewrite);
-  if (nvec > arraysize(vec))
+  if (nvec > static_cast<int>(arraysize(vec)))
     return false;
 
   if (!re.Match(text, 0, text.size(), UNANCHORED, vec, nvec))
@@ -816,7 +816,7 @@
   StringPiece stkvec[kVecSize];
   StringPiece* heapvec = NULL;
 
-  if (nvec <= arraysize(stkvec)) {
+  if (nvec <= static_cast<int>(arraysize(stkvec))) {
     vec = stkvec;
   } else {
     vec = new StringPiece[nvec];
diff --git a/re2/testing/backtrack.cc b/re2/testing/backtrack.cc
index d535dd4..ae9fd82 100644
--- a/re2/testing/backtrack.cc
+++ b/re2/testing/backtrack.cc
@@ -116,7 +116,7 @@
   endmatch_ = prog_->anchor_end();
   submatch_ = submatch;
   nsubmatch_ = nsubmatch;
-  CHECK(2*nsubmatch_ < arraysize(cap_));
+  CHECK_LT(2*nsubmatch_, static_cast<int>(arraysize(cap_)));
   memset(cap_, 0, sizeof cap_);
 
   // We use submatch_[0] for our own bookkeeping,
@@ -201,7 +201,8 @@
       return false;
 
     case kInstCapture:
-      if (0 <= ip->cap() && ip->cap() < arraysize(cap_)) {
+      if (0 <= ip->cap() &&
+          ip->cap() < static_cast<int>(arraysize(cap_))) {
         // Capture p to register, but save old value.
         const char* q = cap_[ip->cap()];
         cap_[ip->cap()] = p;
diff --git a/re2/testing/charclass_test.cc b/re2/testing/charclass_test.cc
index 7e0169c..a2837a6 100644
--- a/re2/testing/charclass_test.cc
+++ b/re2/testing/charclass_test.cc
@@ -197,7 +197,7 @@
 
 TEST(TestCharClassBuilder, Adds) {
   int nfail = 0;
-  for (int i = 0; i < arraysize(tests); i++) {
+  for (size_t i = 0; i < arraysize(tests); i++) {
     CharClassBuilder ccb;
     CCTest* t = &tests[i];
     for (int j = 0; t->add[j].lo >= 0; j++)
diff --git a/re2/testing/compile_test.cc b/re2/testing/compile_test.cc
index 2accba1..6b77cf9 100644
--- a/re2/testing/compile_test.cc
+++ b/re2/testing/compile_test.cc
@@ -113,7 +113,7 @@
 
 TEST(TestRegexpCompileToProg, Simple) {
   int failed = 0;
-  for (int i = 0; i < arraysize(tests); i++) {
+  for (size_t i = 0; i < arraysize(tests); i++) {
     const re2::Test& t = tests[i];
     Regexp* re = Regexp::Parse(t.regexp, Regexp::PerlX|Regexp::Latin1, NULL);
     if (re == NULL) {
diff --git a/re2/testing/exhaustive_tester.cc b/re2/testing/exhaustive_tester.cc
index 7e5dd14..47950ba 100644
--- a/re2/testing/exhaustive_tester.cc
+++ b/re2/testing/exhaustive_tester.cc
@@ -174,7 +174,7 @@
                const std::string& wrapper) {
   const char* tops[] = { "", "^(?:%s)", "(?:%s)$", "^(?:%s)$" };
 
-  for (int i = 0; i < arraysize(tops); i++) {
+  for (size_t i = 0; i < arraysize(tops); i++) {
     ExhaustiveTest(maxatoms, maxops,
                    Split("", alphabet),
                    RegexpGenerator::EgrepOps(),
diff --git a/re2/testing/filtered_re2_test.cc b/re2/testing/filtered_re2_test.cc
index e54caf7..deef2f8 100644
--- a/re2/testing/filtered_re2_test.cc
+++ b/re2/testing/filtered_re2_test.cc
@@ -144,9 +144,9 @@
 };
 
 void AddRegexpsAndCompile(const char* regexps[],
-                          int n,
+                          size_t n,
                           struct FilterTestVars* v) {
-  for (int i = 0; i < n; i++) {
+  for (size_t i = 0; i < n; i++) {
     int id;
     v->f.Add(regexps[i], v->opts, &id);
   }
@@ -154,18 +154,18 @@
 }
 
 bool CheckExpectedAtoms(const char* atoms[],
-                        int n,
+                        size_t n,
                         const char* testname,
                         struct FilterTestVars* v) {
   std::vector<std::string> expected;
-  for (int i = 0; i < n; i++)
+  for (size_t i = 0; i < n; i++)
     expected.push_back(atoms[i]);
 
   bool pass = expected.size() == v->atoms.size();
 
   std::sort(v->atoms.begin(), v->atoms.end());
   std::sort(expected.begin(), expected.end());
-  for (int i = 0; pass && i < n; i++)
+  for (size_t i = 0; pass && i < n; i++)
       pass = pass && expected[i] == v->atoms[i];
 
   if (!pass) {
@@ -183,10 +183,10 @@
 
 TEST(FilteredRE2Test, AtomTests) {
   int nfail = 0;
-  for (int i = 0; i < arraysize(atom_tests); i++) {
+  for (size_t i = 0; i < arraysize(atom_tests); i++) {
     FilterTestVars v;
     AtomTest* t = &atom_tests[i];
-    int natom, nregexp;
+    size_t nregexp, natom;
     for (nregexp = 0; nregexp < arraysize(t->regexps); nregexp++)
       if (t->regexps[nregexp] == NULL)
         break;
@@ -221,7 +221,7 @@
   // for this test. Adding the EXPECT here to make sure
   // the index we use for the test is for the correct test.
   EXPECT_EQ("CheckEmptyPattern", std::string(t->testname));
-  int nregexp;
+  size_t nregexp;
   for (nregexp = 0; nregexp < arraysize(t->regexps); nregexp++)
     if (t->regexps[nregexp] == NULL)
       break;
@@ -238,7 +238,7 @@
   // We are using the regexps used in one of the atom tests
   // for this test.
   EXPECT_EQ("SubstrAtomRemovesSuperStrInOr", std::string(t->testname));
-  int nregexp;
+  size_t nregexp;
   for (nregexp = 0; nregexp < arraysize(t->regexps); nregexp++)
     if (t->regexps[nregexp] == NULL)
       break;
diff --git a/re2/testing/mimics_pcre_test.cc b/re2/testing/mimics_pcre_test.cc
index 2dbbfa1..01ab41e 100644
--- a/re2/testing/mimics_pcre_test.cc
+++ b/re2/testing/mimics_pcre_test.cc
@@ -58,9 +58,9 @@
 };
 
 TEST(MimicsPCRE, SimpleTests) {
-  for (int i = 0; i < arraysize(tests); i++) {
+  for (size_t i = 0; i < arraysize(tests); i++) {
     const PCRETest& t = tests[i];
-    for (int j = 0; j < 2; j++) {
+    for (size_t j = 0; j < 2; j++) {
       Regexp::ParseFlags flags = Regexp::LikePerl;
       if (j == 0)
         flags = flags | Regexp::Latin1;
@@ -68,7 +68,7 @@
       ASSERT_TRUE(re != NULL) << " " << t.regexp;
       ASSERT_EQ(t.should_match, re->MimicsPCRE())
         << " " << t.regexp << " "
-        << (j==0 ? "latin1" : "utf");
+        << (j == 0 ? "latin1" : "utf");
       re->Decref();
     }
   }
diff --git a/re2/testing/parse_test.cc b/re2/testing/parse_test.cc
index a3289b9..3446526 100644
--- a/re2/testing/parse_test.cc
+++ b/re2/testing/parse_test.cc
@@ -427,20 +427,20 @@
 
 // Test that parser rejects bad regexps.
 TEST(TestParse, InvalidRegexps) {
-  for (int i = 0; i < arraysize(badtests); i++) {
+  for (size_t i = 0; i < arraysize(badtests); i++) {
     ASSERT_TRUE(Regexp::Parse(badtests[i], Regexp::PerlX, NULL) == NULL)
       << " " << badtests[i];
     ASSERT_TRUE(Regexp::Parse(badtests[i], Regexp::NoParseFlags, NULL) == NULL)
       << " " << badtests[i];
   }
-  for (int i = 0; i < arraysize(only_posix); i++) {
+  for (size_t i = 0; i < arraysize(only_posix); i++) {
     ASSERT_TRUE(Regexp::Parse(only_posix[i], Regexp::PerlX, NULL) == NULL)
       << " " << only_posix[i];
     Regexp* re = Regexp::Parse(only_posix[i], Regexp::NoParseFlags, NULL);
     ASSERT_TRUE(re != NULL) << " " << only_posix[i];
     re->Decref();
   }
-  for (int i = 0; i < arraysize(only_perl); i++) {
+  for (size_t i = 0; i < arraysize(only_perl); i++) {
     ASSERT_TRUE(Regexp::Parse(only_perl[i], Regexp::NoParseFlags, NULL) == NULL)
       << " " << only_perl[i];
     Regexp* re = Regexp::Parse(only_perl[i], Regexp::PerlX, NULL);
@@ -451,7 +451,7 @@
 
 // Test that ToString produces original regexp or equivalent one.
 TEST(TestToString, EquivalentParse) {
-  for (int i = 0; i < arraysize(tests); i++) {
+  for (size_t i = 0; i < arraysize(tests); i++) {
     RegexpStatus status;
     Regexp::ParseFlags f = kTestFlags;
     if (tests[i].flags != 0) {
diff --git a/re2/testing/possible_match_test.cc b/re2/testing/possible_match_test.cc
index 438cb41..0ec90ae 100644
--- a/re2/testing/possible_match_test.cc
+++ b/re2/testing/possible_match_test.cc
@@ -107,8 +107,8 @@
 };
 
 TEST(PossibleMatchRange, HandWritten) {
-  for (int i = 0; i < arraysize(tests); i++) {
-    for (int j = 0; j < 2; j++) {
+  for (size_t i = 0; i < arraysize(tests); i++) {
+    for (size_t j = 0; j < 2; j++) {
       const PrefixTest& t = tests[i];
       std::string min, max;
       if (j == 0) {
diff --git a/re2/testing/re2_test.cc b/re2/testing/re2_test.cc
index 52c9294..2f4b90c 100644
--- a/re2/testing/re2_test.cc
+++ b/re2/testing/re2_test.cc
@@ -519,7 +519,7 @@
     "[^\\D\\d]",
     "[^\\D[:digit:]]"
   };
-  for (int i = 0; i < arraysize(empties); i++)
+  for (size_t i = 0; i < arraysize(empties); i++)
     ASSERT_FALSE(RE2(empties[i]).Match("abc", 0, 3, RE2::UNANCHORED, NULL, 0));
 }
 
@@ -534,7 +534,7 @@
     "((((()))))" "(([^\\S\\s]|[^\\S\\s])|)"
   };
   StringPiece group[6];
-  for (int i = 0; i < arraysize(nop_empties); i++)
+  for (size_t i = 0; i < arraysize(nop_empties); i++)
     ASSERT_TRUE(RE2(nop_empties[i]).Match("", 0, 0, RE2::UNANCHORED, group, 6));
 }
 
@@ -1297,7 +1297,7 @@
   { "zz(?P<name\377>abc)", "" },
 };
 TEST(RE2, ErrorArgs) {
-  for (int i = 0; i < arraysize(error_tests); i++) {
+  for (size_t i = 0; i < arraysize(error_tests); i++) {
     RE2 re(error_tests[i].regexp, RE2::Quiet);
     EXPECT_FALSE(re.ok());
     EXPECT_EQ(re.error_arg(), error_tests[i].error) << re.error();
@@ -1319,7 +1319,7 @@
 TEST(RE2, NeverNewline) {
   RE2::Options opt;
   opt.set_never_nl(true);
-  for (int i = 0; i < arraysize(never_tests); i++) {
+  for (size_t i = 0; i < arraysize(never_tests); i++) {
     const NeverTest& t = never_tests[i];
     RE2 re(t.regexp, opt);
     if (t.match == NULL) {
@@ -1454,18 +1454,18 @@
   // matches[0] is overall match, [1] is (), [2] is (foo), [3] is nonexistent.
   StringPiece matches[4];
 
-  for (int i = 0; i < arraysize(matches); i++)
+  for (size_t i = 0; i < arraysize(matches); i++)
     matches[i] = "bar";
 
   StringPiece null;
   EXPECT_TRUE(re.Match(null, 0, null.size(), RE2::UNANCHORED,
                        matches, arraysize(matches)));
-  for (int i = 0; i < arraysize(matches); i++) {
+  for (size_t i = 0; i < arraysize(matches); i++) {
     EXPECT_TRUE(matches[i].data() == NULL);  // always null
     EXPECT_TRUE(matches[i].empty());
   }
 
-  for (int i = 0; i < arraysize(matches); i++)
+  for (size_t i = 0; i < arraysize(matches); i++)
     matches[i] = "bar";
 
   StringPiece empty("");
diff --git a/re2/testing/required_prefix_test.cc b/re2/testing/required_prefix_test.cc
index 749c5ad..5460045 100644
--- a/re2/testing/required_prefix_test.cc
+++ b/re2/testing/required_prefix_test.cc
@@ -40,9 +40,9 @@
 };
 
 TEST(RequiredPrefix, SimpleTests) {
-  for (int i = 0; i < arraysize(tests); i++) {
+  for (size_t i = 0; i < arraysize(tests); i++) {
     const PrefixTest& t = tests[i];
-    for (int j = 0; j < 2; j++) {
+    for (size_t j = 0; j < 2; j++) {
       Regexp::ParseFlags flags = Regexp::LikePerl;
       if (j == 0)
         flags = flags | Regexp::Latin1;
@@ -53,15 +53,15 @@
       bool f;
       Regexp* s;
       ASSERT_EQ(t.return_value, re->RequiredPrefix(&p, &f, &s))
-        << " " << t.regexp << " " << (j==0 ? "latin1" : "utf")
+        << " " << t.regexp << " " << (j == 0 ? "latin1" : "utf")
         << " " << re->Dump();
       if (t.return_value) {
         ASSERT_EQ(p, std::string(t.prefix))
-          << " " << t.regexp << " " << (j==0 ? "latin1" : "utf");
+          << " " << t.regexp << " " << (j == 0 ? "latin1" : "utf");
         ASSERT_EQ(f, t.foldcase)
-          << " " << t.regexp << " " << (j==0 ? "latin1" : "utf");
+          << " " << t.regexp << " " << (j == 0 ? "latin1" : "utf");
         ASSERT_EQ(s->ToString(), std::string(t.suffix))
-          << " " << t.regexp << " " << (j==0 ? "latin1" : "utf");
+          << " " << t.regexp << " " << (j == 0 ? "latin1" : "utf");
         s->Decref();
       }
       re->Decref();
diff --git a/re2/testing/search_test.cc b/re2/testing/search_test.cc
index 43a3952..c20f501 100644
--- a/re2/testing/search_test.cc
+++ b/re2/testing/search_test.cc
@@ -312,7 +312,7 @@
 
 TEST(Regexp, SearchTests) {
   int failures = 0;
-  for (int i = 0; i < arraysize(simple_tests); i++) {
+  for (size_t i = 0; i < arraysize(simple_tests); i++) {
     const RegexpTest& t = simple_tests[i];
     if (!TestRegexpOnText(t.regexp, t.text))
       failures++;
diff --git a/re2/testing/simplify_test.cc b/re2/testing/simplify_test.cc
index ede0f32..9dcd4ac 100644
--- a/re2/testing/simplify_test.cc
+++ b/re2/testing/simplify_test.cc
@@ -245,7 +245,7 @@
 };
 
 TEST(TestSimplify, SimpleRegexps) {
-  for (int i = 0; i < arraysize(tests); i++) {
+  for (size_t i = 0; i < arraysize(tests); i++) {
     RegexpStatus status;
     VLOG(1) << "Testing " << tests[i].regexp;
     Regexp* re = Regexp::Parse(tests[i].regexp,
diff --git a/re2/testing/tester.cc b/re2/testing/tester.cc
index 92b5972..d676d9a 100644
--- a/re2/testing/tester.cc
+++ b/re2/testing/tester.cc
@@ -158,7 +158,7 @@
 };
 
 static std::string FormatMode(Regexp::ParseFlags flags) {
-  for (int i = 0; i < arraysize(parse_modes); i++)
+  for (size_t i = 0; i < arraysize(parse_modes); i++)
     if (parse_modes[i].parse_flags == flags)
       return parse_modes[i].desc;
   return StringPrintf("%#x", static_cast<uint32_t>(flags));
@@ -610,8 +610,8 @@
 // Test all possible match kinds and parse modes.
 Tester::Tester(const StringPiece& regexp) {
   error_ = false;
-  for (int i = 0; i < arraysize(kinds); i++) {
-    for (int j = 0; j < arraysize(parse_modes); j++) {
+  for (size_t i = 0; i < arraysize(kinds); i++) {
+    for (size_t j = 0; j < arraysize(parse_modes); j++) {
       TestInstance* t = new TestInstance(regexp, kinds[i],
                                          parse_modes[j].parse_flags);
       error_ |= t->error();
@@ -655,7 +655,7 @@
 bool Tester::TestInputInContext(const StringPiece& text,
                                 const StringPiece& context) {
   bool okay = true;
-  for (int i = 0; i < arraysize(anchors); i++)
+  for (size_t i = 0; i < arraysize(anchors); i++)
     okay &= TestCase(text, context, anchors[i]);
   return okay;
 }
diff --git a/util/util.h b/util/util.h
index 3f75794..8f3e0d0 100644
--- a/util/util.h
+++ b/util/util.h
@@ -5,7 +5,7 @@
 #ifndef UTIL_UTIL_H_
 #define UTIL_UTIL_H_
 
-#define arraysize(array) (int)(sizeof(array)/sizeof((array)[0]))
+#define arraysize(array) (sizeof(array)/sizeof((array)[0]))
 
 #ifndef ATTRIBUTE_NORETURN
 #if defined(__GNUC__)