diff --git a/src/plugins/diffeditor/diffutils.cpp b/src/plugins/diffeditor/diffutils.cpp
index c728981e30756db0d969b09017e03687748962d7..ed15a283d3f0a4705756f3b1380e05e6ddbe510b 100644
--- a/src/plugins/diffeditor/diffutils.cpp
+++ b/src/plugins/diffeditor/diffutils.cpp
@@ -309,9 +309,11 @@ void addChangedPositions(int positionOffset, const QMap<int, int> &originalChang
         const int endPos = it.value();
         const int newStartPos = startPos < 0 ? -1 : startPos + positionOffset;
         const int newEndPos = endPos < 0 ? -1 : endPos + positionOffset;
-        if (startPos < 0 && !changedPositions->isEmpty())
-            changedPositions->insert(changedPositions->lastKey(), newEndPos);
-        else
+        if (startPos < 0 && !changedPositions->isEmpty()) {
+           QMap<int, int>::iterator last = changedPositions->end();
+           --last;
+           last.value() = newEndPos;
+        } else
             changedPositions->insert(newStartPos, newEndPos);
     }
 }