Commit 0be7c8d0 authored by Maksim Ivanov's avatar Maksim Ivanov Committed by Commit Bot

DCHECK on self-assignment of PolicyMap

Add debug assertions against misuses of PolicyMap in self-assignment or
self-modifying constructions.

This CL doesn't bring proper support of such scenarios, but should at
least make it more obvious that they're not supported (by documenting
it and by catching during automated tests).

Bug: none
Change-Id: I9e8a60e48986fd5e3b61b15792b2a24cd6067b9e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2233238
Commit-Queue: Maksim Ivanov <emaxx@chromium.org>
Reviewed-by: default avatarAya Elsayed <ayaelattar@google.com>
Cr-Commit-Position: refs/heads/master@{#775711}
parent 919b773d
......@@ -284,6 +284,8 @@ void PolicyMap::Swap(PolicyMap* other) {
}
void PolicyMap::CopyFrom(const PolicyMap& other) {
DCHECK_NE(this, &other);
Clear();
for (const auto& it : other)
Set(it.first, it.second.DeepCopy());
......@@ -296,6 +298,8 @@ std::unique_ptr<PolicyMap> PolicyMap::DeepCopy() const {
}
void PolicyMap::MergeFrom(const PolicyMap& other) {
DCHECK_NE(this, &other);
for (const auto& policy_and_entry : other) {
Entry* current_policy = GetMutableUntrusted(policy_and_entry.first);
Entry other_policy = policy_and_entry.second.DeepCopy();
......
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