Fix for undefined behaviour in CCollection::erase.

This commit is contained in:
Mat Sutcliffe
2019-05-07 15:11:40 +01:00
committed by Klaus Basan
parent 9c07326462
commit 470a0b27f5

View File

@@ -207,14 +207,17 @@ namespace BlackMisc
//! Remove the element pointed to by the given iterator.
//! \return An iterator to the position of the next element after the one removed.
//! \fixme Relying on implementation detail of QMap to reinterpret_cast to the necessary iterator type.
iterator erase(iterator pos) { return m_impl.erase(reinterpret_cast<QMapNode<T, T> *&>(pos)); }
iterator erase(iterator pos)
{
return m_impl.erase(const_cast<QMapNode<T, T> *&>(reinterpret_cast<const QMapNode<T, T> *&>(pos)));
}
//! Remove the range of elements between two iterators.
//! \return An iterator to the position of the next element after the one removed.
//! \fixme Relying on implementation detail of QMap to reinterpret_cast to the necessary iterator type.
iterator erase(iterator it1, iterator it2)
{
while (it1 != it2) { it1 = m_impl.erase(reinterpret_cast<QMapNode<T, T> *&>(it1)); }
while (it1 != it2) { it1 = erase(it1); }
return it1;
}