diff --git a/Framework/Algorithms/src/Stitch1D.cpp b/Framework/Algorithms/src/Stitch1D.cpp
index cc52e67252841e6ca47ad47f78b53dbf4559fb57..80b11d57b6181a128e5fdc186784f09cd8b20be1 100644
--- a/Framework/Algorithms/src/Stitch1D.cpp
+++ b/Framework/Algorithms/src/Stitch1D.cpp
@@ -429,13 +429,15 @@ void Stitch1D::sortXAxis(MatrixWorkspace_sptr &ws) {
     Mantid::MantidVec vece(ws_size);
     Mantid::MantidVec vecdx(ws_size);
     int l = 0;
-    for (auto it = sorter.cbegin(); it != sorter.cend(); ++it) {
+    auto it = sorter.cbegin();
+    while (it != sorter.cend()) {
       vecx[l] = it->first;
       vecy[l] = it->second;
       vece[l] = (++it)->second;
       if (ws->hasDx(i))
         vecdx[l] = (++it)->second;
       ++l;
+      ++it;
     }
     auto x = make_cow<HistogramX>(std::move(vecx));
     auto y = make_cow<HistogramY>(std::move(vecy));