Fix nullptr deref evaluating train in slot conditional order with no slot

See: #360
This commit is contained in:
Jonathan G Rennison
2022-01-17 00:59:15 +00:00
parent 6197baee9c
commit 79db533abb

View File

@@ -2814,14 +2814,16 @@ VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v, boo
} }
case OCV_TRAIN_IN_SLOT: { case OCV_TRAIN_IN_SLOT: {
TraceRestrictSlot* slot = TraceRestrictSlot::GetIfValid(order->GetXData()); TraceRestrictSlot* slot = TraceRestrictSlot::GetIfValid(order->GetXData());
bool occupant = slot->IsOccupant(v->index); if (slot != nullptr) {
if (occ == OCC_EQUALS || occ == OCC_NOT_EQUALS) { bool occupant = slot->IsOccupant(v->index);
if (!occupant && !dry_run) { if (occ == OCC_EQUALS || occ == OCC_NOT_EQUALS) {
occupant = slot->Occupy(v->index); if (!occupant && !dry_run) {
occupant = slot->Occupy(v->index);
}
occ = (occ == OCC_EQUALS) ? OCC_IS_TRUE : OCC_IS_FALSE;
} }
occ = (occ == OCC_EQUALS) ? OCC_IS_TRUE : OCC_IS_FALSE; skip_order = OrderConditionCompare(occ, occupant, value);
} }
if (slot != nullptr) skip_order = OrderConditionCompare(occ, occupant, value);
break; break;
} }
case OCV_FREE_PLATFORMS: { case OCV_FREE_PLATFORMS: {