Change LogIndexOutOfBoundsAndAbort logging message. PiperOrigin-RevId: 813931298
diff --git a/src/google/protobuf/repeated_field.cc b/src/google/protobuf/repeated_field.cc index 1487402..e47ec62 100644 --- a/src/google/protobuf/repeated_field.cc +++ b/src/google/protobuf/repeated_field.cc
@@ -35,7 +35,8 @@ } void LogIndexOutOfBoundsAndAbort(int index, int size) { - ABSL_LOG(FATAL) << "index: " << index << ", size: " << size; + ABSL_LOG(FATAL) << "Index (" << index + << ") out of bounds of container with size (" << size << ")"; } } // namespace internal
diff --git a/src/google/protobuf/repeated_field_unittest.cc b/src/google/protobuf/repeated_field_unittest.cc index e480f6a..8e5b8be 100644 --- a/src/google/protobuf/repeated_field_unittest.cc +++ b/src/google/protobuf/repeated_field_unittest.cc
@@ -1362,15 +1362,18 @@ RepeatedField<int> field; // Empty container tests. - EXPECT_DEATH(CheckedMutableOrAbort(&field, -1), "index: -1, size: 0"); + EXPECT_DEATH(CheckedMutableOrAbort(&field, -1), + "Index \\(-1\\) out of bounds of container with size \\(0\\)"); EXPECT_DEATH(CheckedMutableOrAbort(&field, field.size()), - "index: 0, size: 0"); + "Index \\(0\\) out of bounds of container with size \\(0\\)"); // Non-empty container tests field.Add(5); field.Add(4); - EXPECT_DEATH(CheckedMutableOrAbort(&field, 2), "index: 2, size: 2"); - EXPECT_DEATH(CheckedMutableOrAbort(&field, -1), "index: -1, size: 2"); + EXPECT_DEATH(CheckedMutableOrAbort(&field, 2), + "Index \\(2\\) out of bounds of container with size \\(2\\)"); + EXPECT_DEATH(CheckedMutableOrAbort(&field, -1), + "Index \\(-1\\) out of bounds of container with size \\(2\\)"); } } // namespace
diff --git a/src/google/protobuf/repeated_ptr_field_unittest.cc b/src/google/protobuf/repeated_ptr_field_unittest.cc index dfdf1b4..2453c3e 100644 --- a/src/google/protobuf/repeated_ptr_field_unittest.cc +++ b/src/google/protobuf/repeated_ptr_field_unittest.cc
@@ -1186,15 +1186,18 @@ RepeatedPtrField<std::string> field; // Empty container tests. - EXPECT_DEATH(internal::CheckedGetOrAbort(field, -1), "index: -1, size: 0"); + EXPECT_DEATH(internal::CheckedGetOrAbort(field, -1), + "Index \\(-1\\) out of bounds of container with size \\(0\\)"); EXPECT_DEATH(internal::CheckedGetOrAbort(field, field.size()), - "index: 0, size: 0"); + "Index \\(0\\) out of bounds of container with size \\(0\\)"); // Non-empty container tests field.Add()->assign("foo"); field.Add()->assign("bar"); - EXPECT_DEATH(internal::CheckedGetOrAbort(field, 2), "index: 2, size: 2"); - EXPECT_DEATH(internal::CheckedGetOrAbort(field, -1), "index: -1, size: 2"); + EXPECT_DEATH(internal::CheckedGetOrAbort(field, 2), + "Index \\(2\\) out of bounds of container with size \\(2\\)"); + EXPECT_DEATH(internal::CheckedGetOrAbort(field, -1), + "Index \\(-1\\) out of bounds of container with size \\(2\\)"); } TEST(RepeatedPtrFieldDeathTest, CheckedMutableOrAbortTest) { @@ -1202,16 +1205,17 @@ // Empty container tests. EXPECT_DEATH(internal::CheckedMutableOrAbort(&field, -1), - "index: -1, size: 0"); + "Index \\(-1\\) out of bounds of container with size \\(0\\)"); EXPECT_DEATH(internal::CheckedMutableOrAbort(&field, field.size()), - "index: 0, size: 0"); + "Index \\(0\\) out of bounds of container with size \\(0\\)"); // Non-empty container tests field.Add()->assign("foo"); field.Add()->assign("bar"); - EXPECT_DEATH(internal::CheckedMutableOrAbort(&field, 2), "index: 2, size: 2"); + EXPECT_DEATH(internal::CheckedMutableOrAbort(&field, 2), + "Index \\(2\\) out of bounds of container with size \\(2\\)"); EXPECT_DEATH(internal::CheckedMutableOrAbort(&field, -1), - "index: -1, size: 2"); + "Index \\(-1\\) out of bounds of container with size \\(2\\)"); } // ===================================================================