Commit cb342ec3 authored by Dmitry Kazakov's avatar Dmitry Kazakov
Browse files

Fix all invalid accesses in stl-like iterators

We must not keep 'end' iterator throughout the loop if the object
is changed in the meantime. According to Qt's docs all the iterators
become 'undefined' after every non-const function call over the
iterated object.

CC:kimageshop@kde.org
parent 44c827d7
......@@ -127,10 +127,7 @@ bool KoSnapGuide::addCustomSnapStrategy(KoSnapStrategy *customStrategy)
void KoSnapGuide::overrideSnapStrategy(Strategy type, KoSnapStrategy *strategy)
{
Private::StrategiesList::iterator it = d->strategies.begin();
Private::StrategiesList::iterator end = d->strategies.end();
while (it != end) {
for (auto it = d->strategies.begin(); it != d->strategies.end(); /*noop*/) {
if ((*it)->type() == type) {
if (strategy) {
*it = toQShared(strategy);
......
......@@ -1031,9 +1031,7 @@ namespace KisLayerUtils {
{
QList<KisSelectionMaskSP> selectionMasks;
KisNodeList::iterator it = mergedNodes.begin();
KisNodeList::iterator end = mergedNodes.end();
while (it != end) {
for (auto it = mergedNodes.begin(); it != mergedNodes.end(); /*noop*/) {
KisSelectionMaskSP mask = dynamic_cast<KisSelectionMask*>(it->data());
if (!mask) {
it = mergedNodes.erase(it);
......
......@@ -82,17 +82,6 @@ public:
return pi;
}
/*vQPointF map(vQPointF v) const {
vQPointF::iterator it = v.begin();
vQPointF::iterator end = v.end();
while (it != end) {
*it = m_transform.map(*it);
}
return v;
}*/
template <class T>
T map(const T &object) const {
return m_transform.map(object);
......
......@@ -1857,8 +1857,8 @@ KisPaintDeviceFramesInterface::testingGetDataObjects() const
typedef KisPaintDevice::Private::FramesHash FramesHash;
FramesHash::iterator it = q->m_d->m_frames.begin();
FramesHash::iterator end = q->m_d->m_frames.end();
FramesHash::const_iterator it = q->m_d->m_frames.constBegin();
FramesHash::const_iterator end = q->m_d->m_frames.constEnd();
for (; it != end; ++it) {
objects.m_frames.insert(it.key(), it.value().data());
......
......@@ -391,36 +391,18 @@ namespace KritaUtils
continue;
}
QList<QPainterPath>::iterator it = resultList.begin();
QList<QPainterPath>::iterator end = resultList.end();
QList<QPainterPath>::iterator savedIt = end;
bool wasMerged = false;
while (it != end) {
bool skipIncrement = false;
QPainterPath mergedPath = testPath;
for (auto it = resultList.begin(); it != resultList.end(); /*noop*/) {
if (it->intersects(testPath)) {
if (savedIt == end) {
it->addPath(testPath);
savedIt = it;
} else {
savedIt->addPath(*it);
it = resultList.erase(it);
skipIncrement = true;
}
wasMerged = true;
}
if (!skipIncrement) {
mergedPath.addPath(*it);
it = resultList.erase(it);
} else {
++it;
}
}
if (!wasMerged) {
resultList.append(testPath);
}
resultList.append(mergedPath);
}
return resultList;
......
......@@ -306,11 +306,8 @@ void KisRecordedPaintAction::play(KisNodeSP node, const KisPlayInfo& info, KoUpd
painter2.setOpacity(d->opacity * 255);
QVector<QRect> dirtyRects = painter->takeDirtyRegion();
QVector<QRect>::iterator it = dirtyRects.begin();
QVector<QRect>::iterator end = dirtyRects.end();
while (it != end) {
painter2.bitBlt(it->topLeft(), target, *it);
++it;
Q_FOREACH (const QRect &rc, dirtyRects) {
painter2.bitBlt(rc.topLeft(), target, rc);
}
node->setDirty(painter2.takeDirtyRegion());
......
......@@ -233,12 +233,9 @@ void KoColorSet::add(const KoColorSetEntry & c)
void KoColorSet::remove(const KoColorSetEntry & c)
{
QVector<KoColorSetEntry>::iterator it = m_colors.begin();
QVector<KoColorSetEntry>::iterator end = m_colors.end();
while (it != end) {
for (auto it = m_colors.begin(); it != m_colors.end(); /*noop*/) {
if ((*it) == c) {
m_colors.erase(it);
it = m_colors.erase(it);
return;
}
++it;
......
......@@ -186,10 +186,8 @@ bool KisInputManager::eventFilter(QObject* object, QEvent* event)
if (d->eventEater.eventFilter(object, event)) return false;
if (!d->matcher.hasRunningShortcut()) {
Private::PriorityList::iterator it = d->priorityEventFilter.begin();
Private::PriorityList::iterator end = d->priorityEventFilter.end();
while (it != end) {
for (auto it = d->priorityEventFilter.begin(); it != d->priorityEventFilter.end(); /*noop*/) {
const QPointer<QObject> &filter = it->second;
if (filter.isNull()) {
......
......@@ -133,8 +133,8 @@ void TimelineDocker::setMainWindow(KisViewManager *view)
QMap<QString, KisAction*> actions = m_d->view->globalActions();
QMap<QString, KisAction*>::iterator it = actions.begin();
QMap<QString, KisAction*>::iterator end = actions.end();
QMap<QString, KisAction*>::const_iterator it = actions.constBegin();
QMap<QString, KisAction*>::const_iterator end = actions.constEnd();
for (; it != end; ++it) {
actionManager->addAction(it.key(), it.value());
......
......@@ -775,10 +775,7 @@ void TimelineFramesView::slotRemoveFrame()
{
QModelIndexList indexes = selectionModel()->selectedIndexes();
QModelIndexList::iterator it = indexes.begin();
QModelIndexList::iterator end = indexes.end();
while (it != end) {
for (auto it = indexes.begin(); it != indexes.end(); /*noop*/) {
if (!m_d->model->data(*it, TimelineFramesModel::FrameEditableRole).toBool()) {
it = indexes.erase(it);
} else {
......
......@@ -684,8 +684,8 @@ KisImageBuilder_Result exrConverter::decode(const QString &filename)
else if (info.channelMap.size() == 2) {
modelId = GrayAColorModelID.id();
QMap<QString,QString>::iterator it = info.channelMap.begin();
QMap<QString,QString>::iterator end = info.channelMap.end();
QMap<QString,QString>::const_iterator it = info.channelMap.constBegin();
QMap<QString,QString>::const_iterator end = info.channelMap.constEnd();
QString failingChannelKey;
......
......@@ -206,22 +206,13 @@ void ToolTransformArgs::translate(const QPointF &offset)
m_rotationCenterOffset += offset;
m_transformedCenter += offset;
} else if(m_mode == WARP || m_mode == CAGE) {
{
QVector<QPointF>::iterator it = m_origPoints.begin();
QVector<QPointF>::iterator end = m_origPoints.end();
for (; it != end; ++it) {
*it += offset;
}
for (auto &pt : m_origPoints) {
pt += offset;
}
{
QVector<QPointF>::iterator it = m_transfPoints.begin();
QVector<QPointF>::iterator end = m_transfPoints.end();
for (; it != end; ++it) {
*it += offset;
}
for (auto &pt : m_transfPoints) {
pt += offset;
}
} else if (m_mode == LIQUIFY) {
KIS_ASSERT_RECOVER_RETURN(m_liquifyWorker);
m_liquifyWorker->translate(offset);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment