summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-06-28 17:29:20 -0700
committerTobrun <tobrun.van.nuland@gmail.com>2017-07-05 20:15:17 +0200
commit87081b8391edb3a5e3bd0dede45534f191d1f84a (patch)
tree1832247c88768628a0f822cac7ff1f6137f4aaa4
parent14c221fce77ce5041e16db8a40081cbcc54a1902 (diff)
downloadqtlocation-mapboxgl-87081b8391edb3a5e3bd0dede45534f191d1f84a.tar.gz
[core] Fix iterator invalidation in erase_if
vector::erase invalidates iterators. It's not safe for erase_if to cache the end iterator nor increment, then erase.
-rw-r--r--src/mbgl/util/std.hpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/mbgl/util/std.hpp b/src/mbgl/util/std.hpp
index 974e21329c..1db20e09e5 100644
--- a/src/mbgl/util/std.hpp
+++ b/src/mbgl/util/std.hpp
@@ -8,10 +8,10 @@ namespace mbgl {
namespace util {
template <typename Container, typename ForwardIterator, typename Predicate>
-void erase_if(Container &container, ForwardIterator it, const ForwardIterator end, Predicate pred) {
- while (it != end) {
+void erase_if(Container &container, ForwardIterator it, Predicate pred) {
+ while (it != container.end()) {
if (pred(*it)) {
- container.erase(it++);
+ it = container.erase(it);
} else {
++it;
}
@@ -20,7 +20,7 @@ void erase_if(Container &container, ForwardIterator it, const ForwardIterator en
template <typename Container, typename Predicate>
void erase_if(Container &container, Predicate pred) {
- erase_if(container, container.begin(), container.end(), pred);
+ erase_if(container, container.begin(), pred);
}
} // namespace util