From d5e936c9d4a0583d8cd8e8719ee573c7fbcaca54 Mon Sep 17 00:00:00 2001 From: Tyler Trahan Date: Sun, 4 Feb 2024 01:07:47 -0500 Subject: [PATCH] Fix #11968: Always set string parameters to avoid undefined behavior (#11973) --- src/order_gui.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/order_gui.cpp b/src/order_gui.cpp index e916d3d72f..fc889d3fe0 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -1166,7 +1166,11 @@ public: case WID_O_DEPOT_ACTION: { VehicleOrderID sel = this->OrderGetSel(); const Order *order = this->vehicle->GetOrder(sel); - if (order == nullptr || !order->IsType(OT_GOTO_DEPOT)) break; + if (order == nullptr || !order->IsType(OT_GOTO_DEPOT)) { + /* We can't leave this param unset or the undefined behavior can cause a crash. */ + SetDParam(0, STR_EMPTY); + break; + }; /* Select the current action selected in the dropdown. The flags don't match the dropdown so we can't just use an index. */ if (order->GetDepotOrderType() & ODTFB_SERVICE) {