[krita] /: Fix all invalid accesses in stl-like iterators
Dmitry Kazakov
dimula73 at gmail.com
Fri Apr 15 16:07:28 UTC 2016
Git commit cb342ec320ad79c07c9d8963895ff963f841eb3f by Dmitry Kazakov.
Committed on 15/04/2016 at 16:04.
Pushed by dkazakov into branch 'master'.
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 at kde.org
M +1 -4 libs/flake/KoSnapGuide.cpp
M +1 -3 libs/image/kis_layer_utils.cpp
M +0 -11 libs/image/kis_lod_transform.h
M +2 -2 libs/image/kis_paint_device.cc
M +6 -24 libs/image/krita_utils.cpp
M +2 -5 libs/image/recorder/kis_recorded_paint_action.cpp
M +2 -5 libs/pigment/resources/KoColorSet.cpp
M +1 -3 libs/ui/input/kis_input_manager.cpp
M +2 -2 plugins/dockers/animation/timeline_docker.cpp
M +1 -4 plugins/dockers/animation/timeline_frames_view.cpp
M +2 -2 plugins/impex/exr/exr_converter.cc
M +4 -13 plugins/tools/tool_transform2/tool_transform_args.cc
http://commits.kde.org/krita/cb342ec320ad79c07c9d8963895ff963f841eb3f
diff --git a/libs/flake/KoSnapGuide.cpp b/libs/flake/KoSnapGuide.cpp
index 7e041d3..f26e914 100644
--- a/libs/flake/KoSnapGuide.cpp
+++ b/libs/flake/KoSnapGuide.cpp
@@ -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);
diff --git a/libs/image/kis_layer_utils.cpp b/libs/image/kis_layer_utils.cpp
index 369b65c..125e522 100644
--- a/libs/image/kis_layer_utils.cpp
+++ b/libs/image/kis_layer_utils.cpp
@@ -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);
diff --git a/libs/image/kis_lod_transform.h b/libs/image/kis_lod_transform.h
index ca2910a..5d2364e 100644
--- a/libs/image/kis_lod_transform.h
+++ b/libs/image/kis_lod_transform.h
@@ -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);
diff --git a/libs/image/kis_paint_device.cc b/libs/image/kis_paint_device.cc
index f5e85bd..66b856c 100644
--- a/libs/image/kis_paint_device.cc
+++ b/libs/image/kis_paint_device.cc
@@ -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());
diff --git a/libs/image/krita_utils.cpp b/libs/image/krita_utils.cpp
index 7be7cd4..44b148e 100644
--- a/libs/image/krita_utils.cpp
+++ b/libs/image/krita_utils.cpp
@@ -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;
diff --git a/libs/image/recorder/kis_recorded_paint_action.cpp b/libs/image/recorder/kis_recorded_paint_action.cpp
index 8ad95f3..330b2e6 100644
--- a/libs/image/recorder/kis_recorded_paint_action.cpp
+++ b/libs/image/recorder/kis_recorded_paint_action.cpp
@@ -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());
diff --git a/libs/pigment/resources/KoColorSet.cpp b/libs/pigment/resources/KoColorSet.cpp
index dbf204b..d4747e3 100644
--- a/libs/pigment/resources/KoColorSet.cpp
+++ b/libs/pigment/resources/KoColorSet.cpp
@@ -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;
diff --git a/libs/ui/input/kis_input_manager.cpp b/libs/ui/input/kis_input_manager.cpp
index 79ea3bf..ff23241 100644
--- a/libs/ui/input/kis_input_manager.cpp
+++ b/libs/ui/input/kis_input_manager.cpp
@@ -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()) {
diff --git a/plugins/dockers/animation/timeline_docker.cpp b/plugins/dockers/animation/timeline_docker.cpp
index 35e2288..f4f1ca9 100644
--- a/plugins/dockers/animation/timeline_docker.cpp
+++ b/plugins/dockers/animation/timeline_docker.cpp
@@ -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());
diff --git a/plugins/dockers/animation/timeline_frames_view.cpp b/plugins/dockers/animation/timeline_frames_view.cpp
index 6887df3..86376b9 100644
--- a/plugins/dockers/animation/timeline_frames_view.cpp
+++ b/plugins/dockers/animation/timeline_frames_view.cpp
@@ -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 {
diff --git a/plugins/impex/exr/exr_converter.cc b/plugins/impex/exr/exr_converter.cc
index 667dd07..69291f2 100644
--- a/plugins/impex/exr/exr_converter.cc
+++ b/plugins/impex/exr/exr_converter.cc
@@ -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;
diff --git a/plugins/tools/tool_transform2/tool_transform_args.cc b/plugins/tools/tool_transform2/tool_transform_args.cc
index 2af9e3c..62f30c2 100644
--- a/plugins/tools/tool_transform2/tool_transform_args.cc
+++ b/plugins/tools/tool_transform2/tool_transform_args.cc
@@ -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);
More information about the kimageshop
mailing list