Use lower_bound instead of equal_range in StationCargoList::ShiftCargo

Calling erase could potentially invalidate the upper_bound iterator
This commit is contained in:
Jonathan G Rennison
2020-05-10 15:17:36 +01:00
parent ea8a89e377
commit 1c768705a1

View File

@@ -906,8 +906,7 @@ void StationCargoList::Append(CargoPacket *cp, StationID next)
template <class Taction> template <class Taction>
bool StationCargoList::ShiftCargo(Taction &action, StationID next) bool StationCargoList::ShiftCargo(Taction &action, StationID next)
{ {
std::pair<Iterator, Iterator> range(this->packets.equal_range(next)); for (Iterator it = this->packets.lower_bound(next); it != this->packets.end() && it.GetKey() == next;) {
for (Iterator it(range.first); it != range.second && it.GetKey() == next;) {
if (action.MaxMove() == 0) return false; if (action.MaxMove() == 0) return false;
CargoPacket *cp = *it; CargoPacket *cp = *it;
if (action(cp)) { if (action(cp)) {