Commit 1534fb74 authored by Varun Khaneja's avatar Varun Khaneja Committed by Commit Bot

Add more CHECKs and use .at() to access a value in the map

Bug: 787460
Change-Id: Ic2666e71531b6f1d593fb8a8fd500d1b42b1f7ce
Reviewed-on: https://chromium-review.googlesource.com/850539
Commit-Queue: Varun Khaneja <vakh@chromium.org>
Reviewed-by: default avatarNathan Parker <nparker@chromium.org>
Cr-Commit-Position: refs/heads/master@{#527151}
parent dcc6ca77
......@@ -494,9 +494,12 @@ bool V4Store::GetNextSmallestUnmergedPrefix(
for (const auto& iterator_pair : iterator_map) {
PrefixSize prefix_size = iterator_pair.first;
CHECK_GE(prefix_size, 4u); // Convert to DCHECK after fixing 787460.
HashPrefixes::const_iterator start = iterator_pair.second;
CHECK(hash_prefix_map.end() != hash_prefix_map.find(prefix_size));
CHECK(hash_prefix_map.end() !=
hash_prefix_map.find(
prefix_size)); // Convert to DCHECK after fixing 787460.
const HashPrefixes& hash_prefixes = hash_prefix_map.at(prefix_size);
PrefixSize distance = std::distance(start, hash_prefixes.end());
......@@ -600,12 +603,14 @@ ApplyUpdateResult V4Store::MergeUpdate(const HashPrefixMap& old_prefixes_map,
// Update the iterator map, which means that we have merged one hash
// prefix of size |next_smallest_prefix_size| from the old store.
old_iterator_map[next_smallest_prefix_size] += next_smallest_prefix_size;
old_iterator_map.at(next_smallest_prefix_size) +=
next_smallest_prefix_size;
if (!raw_removals || removals_iter == raw_removals->end() ||
*removals_iter != total_picked_from_old) {
// Append the smallest hash to the appropriate list.
hash_prefix_map_[next_smallest_prefix_size] += next_smallest_prefix_old;
hash_prefix_map_.at(next_smallest_prefix_size) +=
next_smallest_prefix_old;
if (calculate_checksum) {
checksum_ctx->Update(next_smallest_prefix_old.data(),
......@@ -625,7 +630,7 @@ ApplyUpdateResult V4Store::MergeUpdate(const HashPrefixMap& old_prefixes_map,
next_smallest_prefix_size = next_smallest_prefix_additions.size();
// Append the smallest hash to the appropriate list.
hash_prefix_map_[next_smallest_prefix_size] +=
hash_prefix_map_.at(next_smallest_prefix_size) +=
next_smallest_prefix_additions;
if (calculate_checksum) {
......@@ -635,7 +640,7 @@ ApplyUpdateResult V4Store::MergeUpdate(const HashPrefixMap& old_prefixes_map,
// Update the iterator map, which means that we have merged one hash
// prefix of size |next_smallest_prefix_size| from the update.
additions_iterator_map[next_smallest_prefix_size] +=
additions_iterator_map.at(next_smallest_prefix_size) +=
next_smallest_prefix_size;
// Find the next smallest unmerged element in the additions map.
......@@ -821,6 +826,7 @@ bool V4Store::VerifyChecksum() {
IteratorMap iterator_map;
HashPrefix next_smallest_prefix;
InitializeIteratorMap(hash_prefix_map_, &iterator_map);
CHECK_EQ(hash_prefix_map_.size(), iterator_map.size());
bool has_unmerged = GetNextSmallestUnmergedPrefix(
hash_prefix_map_, iterator_map, &next_smallest_prefix);
......@@ -832,7 +838,7 @@ bool V4Store::VerifyChecksum() {
// Update the iterator map, which means that we have read one hash
// prefix of size |next_smallest_prefix_size| from hash_prefix_map_.
iterator_map[next_smallest_prefix_size] += next_smallest_prefix_size;
iterator_map.at(next_smallest_prefix_size) += next_smallest_prefix_size;
checksum_ctx->Update(next_smallest_prefix.data(),
next_smallest_prefix_size);
......
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