Commit 1ad22093 by Abseil Team Committed by Copybara-Service

Fix a crash when calling `EstimatedMemoryUsage()` on an empty checksummed `absl::Cord`.

PiperOrigin-RevId: 567695227
Change-Id: I13eb8a1872d2fe703b5f3b9bc8df7fec4381fb55
parent 90e8f6f7
......@@ -157,6 +157,9 @@ size_t GetEstimatedUsage(const CordRep* rep) {
// Consume the top level CRC node if present.
if (repref.rep->tag == CRC) {
raw_usage.Add(sizeof(CordRepCrc), repref);
if (repref.rep->crc()->child == nullptr) {
return static_cast<size_t>(raw_usage.total);
}
repref = repref.Child(repref.rep->crc()->child);
}
......
......@@ -3240,6 +3240,12 @@ TEST_P(CordTest, ChecksummedEmptyCord) {
EXPECT_EQ(absl::HashOf(c3), absl::HashOf(absl::string_view()));
}
TEST(CrcCordTest, ChecksummedEmptyCordEstimateMemoryUsage) {
absl::Cord cord;
cord.SetExpectedChecksum(0);
EXPECT_NE(cord.EstimatedMemoryUsage(), 0);
}
#if defined(GTEST_HAS_DEATH_TEST) && defined(ABSL_INTERNAL_CORD_HAVE_SANITIZER)
// Returns an expected poison / uninitialized death message expression.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment