mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-14 04:13:33 +08:00
Safer list traversing in Multiset<> and Map<>
This commit is contained in:
@@ -417,8 +417,10 @@ void MapBase<Key, Value>::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<Key, Value>::removeAllWhere(Predicate predicate)
|
||||
}
|
||||
}
|
||||
}
|
||||
p = p->getNextListNode();
|
||||
|
||||
p = next_group;
|
||||
}
|
||||
|
||||
if (num_removed > 0)
|
||||
@@ -461,8 +464,10 @@ const Key* MapBase<Key, Value>::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<Key, Value>::find(Predicate predicate) const
|
||||
}
|
||||
}
|
||||
}
|
||||
p = p->getNextListNode();
|
||||
|
||||
p = next_group;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -505,8 +511,10 @@ typename MapBase<Key, Value>::KVPair* MapBase<Key, Value>::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<Key, Value>::KVPair* MapBase<Key, Value>::getByIndex(unsigned i
|
||||
index--;
|
||||
}
|
||||
}
|
||||
p = p->getNextListNode();
|
||||
|
||||
p = next_group;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
@@ -435,8 +435,10 @@ void Multiset<T, NumStaticEntries>::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<T, NumStaticEntries>::removeWhere(Predicate predicate, const Remov
|
||||
}
|
||||
}
|
||||
|
||||
p = p->getNextListNode();
|
||||
p = next_chunk;
|
||||
}
|
||||
|
||||
if (num_removed > 0)
|
||||
@@ -486,8 +488,10 @@ T* Multiset<T, NumStaticEntries>::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<T, NumStaticEntries>::find(Predicate predicate)
|
||||
}
|
||||
}
|
||||
}
|
||||
p = p->getNextListNode();
|
||||
|
||||
p = next_chunk;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user