diff --git a/snapshot/sanitized/module_snapshot_sanitized.cc b/snapshot/sanitized/module_snapshot_sanitized.cc index 0ad2ee97..c7672268 100644 --- a/snapshot/sanitized/module_snapshot_sanitized.cc +++ b/snapshot/sanitized/module_snapshot_sanitized.cc @@ -99,9 +99,11 @@ ModuleSnapshotSanitized::AnnotationsSimpleMap() const { std::map annotations = snapshot_->AnnotationsSimpleMap(); if (allowed_annotations_) { - for (auto kv = annotations.begin(); kv != annotations.end(); ++kv) { - if (!KeyIsAllowed(kv->first, *allowed_annotations_)) { - annotations.erase(kv); + for (auto kv = annotations.begin(); kv != annotations.end();) { + if (KeyIsAllowed(kv->first, *allowed_annotations_)) { + ++kv; + } else { + kv = annotations.erase(kv); } } }