diff --git a/libuavcan/include/uavcan/util/map.hpp b/libuavcan/include/uavcan/util/map.hpp index 1f805fa0a2..ece759af0e 100644 --- a/libuavcan/include/uavcan/util/map.hpp +++ b/libuavcan/include/uavcan/util/map.hpp @@ -417,8 +417,10 @@ void MapBase::removeAllWhere(Predicate predicate) #endif KVGroup* p = list_.get(); - while (p) + while (p != NULL) { + KVGroup* const next_group = p->getNextListNode(); + for (int i = 0; i < KVGroup::NumKV; i++) { const KVPair* const kv = p->kvs + i; @@ -431,7 +433,8 @@ void MapBase::removeAllWhere(Predicate predicate) } } } - p = p->getNextListNode(); + + p = next_group; } if (num_removed > 0) @@ -461,8 +464,10 @@ const Key* MapBase::find(Predicate predicate) const #endif KVGroup* p = list_.get(); - while (p) + while (p != NULL) { + KVGroup* const next_group = p->getNextListNode(); + for (int i = 0; i < KVGroup::NumKV; i++) { const KVPair* const kv = p->kvs + i; @@ -474,7 +479,8 @@ const Key* MapBase::find(Predicate predicate) const } } } - p = p->getNextListNode(); + + p = next_group; } return NULL; } @@ -505,8 +511,10 @@ typename MapBase::KVPair* MapBase::getByIndex(unsigned i // Slowly crawling through the dynamic storage KVGroup* p = list_.get(); - while (p) + while (p != NULL) { + KVGroup* const next_group = p->getNextListNode(); + for (int i = 0; i < KVGroup::NumKV; i++) { KVPair* const kv = p->kvs + i; @@ -519,7 +527,8 @@ typename MapBase::KVPair* MapBase::getByIndex(unsigned i index--; } } - p = p->getNextListNode(); + + p = next_group; } return NULL; diff --git a/libuavcan/include/uavcan/util/multiset.hpp b/libuavcan/include/uavcan/util/multiset.hpp index aae7d295f4..90e4bf3d6c 100644 --- a/libuavcan/include/uavcan/util/multiset.hpp +++ b/libuavcan/include/uavcan/util/multiset.hpp @@ -435,8 +435,10 @@ void Multiset::removeWhere(Predicate predicate, const Remov #endif Chunk* p = list_.get(); - while (p) + while (p != NULL) { + Chunk* const next_chunk = p->getNextListNode(); // For the case if the current entry gets modified + if ((num_removed > 0) && (strategy == RemoveOne)) { break; @@ -459,7 +461,7 @@ void Multiset::removeWhere(Predicate predicate, const Remov } } - p = p->getNextListNode(); + p = next_chunk; } if (num_removed > 0) @@ -486,8 +488,10 @@ T* Multiset::find(Predicate predicate) #endif Chunk* p = list_.get(); - while (p) + while (p != NULL) { + Chunk* const next_chunk = p->getNextListNode(); // For the case if the current entry gets modified + for (int i = 0; i < Chunk::NumItems; i++) { if (p->items[i].isConstructed()) @@ -498,7 +502,8 @@ T* Multiset::find(Predicate predicate) } } } - p = p->getNextListNode(); + + p = next_chunk; } return NULL; }