From 1c768705a11673706a8e0e5a149ab6c9ef4366ce Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 10 May 2020 15:17:36 +0100 Subject: [PATCH] Use lower_bound instead of equal_range in StationCargoList::ShiftCargo Calling erase could potentially invalidate the upper_bound iterator --- src/cargopacket.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cargopacket.cpp b/src/cargopacket.cpp index a40f920b07..188d33805a 100644 --- a/src/cargopacket.cpp +++ b/src/cargopacket.cpp @@ -906,8 +906,7 @@ void StationCargoList::Append(CargoPacket *cp, StationID next) template bool StationCargoList::ShiftCargo(Taction &action, StationID next) { - std::pair range(this->packets.equal_range(next)); - for (Iterator it(range.first); it != range.second && it.GetKey() == next;) { + for (Iterator it = this->packets.lower_bound(next); it != this->packets.end() && it.GetKey() == next;) { if (action.MaxMove() == 0) return false; CargoPacket *cp = *it; if (action(cp)) {