diff options
author | Fredrik Roubert <roubert@google.com> | 2014-08-05 17:06:16 +0000 |
---|---|---|
committer | Fredrik Roubert <roubert@google.com> | 2014-09-01 19:20:50 +0200 |
commit | a68fee4c34c39626284b861f34c4b6511961fbdd (patch) | |
tree | ea579513505d9bcd6f091c30b28f12fba83f7384 /cpp | |
parent | 5d648480487cec5b3b1fecb0d45f957abc8529f8 (diff) | |
download | src-a68fee4c34c39626284b861f34c4b6511961fbdd.tar.gz |
Bug fix: Access reference before erasing underlying data, not after ...
R=rouslan@chromium.org
BUG=
Review URL: https://codereview.appspot.com/115640043
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/src/ondemand_supply_task.cc | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/cpp/src/ondemand_supply_task.cc b/cpp/src/ondemand_supply_task.cc index 64568b3..f46d475 100644 --- a/cpp/src/ondemand_supply_task.cc +++ b/cpp/src/ondemand_supply_task.cc @@ -81,21 +81,20 @@ void OndemandSupplyTask::Retrieve(const Retriever& retriever) { void OndemandSupplyTask::Load(bool success, const std::string& key, const std::string& data) { + size_t depth = std::count(key.begin(), key.end(), '/') - 1; + assert(depth < arraysize(LookupKey::kHierarchy)); + // Sanity check: This key should be present in the set of pending requests. size_t status = pending_.erase(key); assert(status == 1); // There will always be one item erased from the set. (void)status; // Prevent unused variable if assert() is optimized away. - size_t depth = std::count(key.begin(), key.end(), '/') - 1; - assert(depth < arraysize(LookupKey::kHierarchy)); - AddressField field = LookupKey::kHierarchy[depth]; - if (success) { // The address metadata server will return the empty JSON "{}" when it // successfully performed a lookup, but didn't find any data for that key. if (data != "{}") { Rule* rule = new Rule; - if (field == COUNTRY) { + if (LookupKey::kHierarchy[depth] == COUNTRY) { // All rules on the COUNTRY level inherit from the default rule. rule->CopyFrom(Rule::GetDefault()); } |