From 36c735ebface9c49c3ac182a44bec8abc794c09f Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Wed, 6 Nov 2024 18:53:48 +0000 Subject: [PATCH] Codefix: Nullptr dereference in industry var 0xB4 when no cargoes accepted (#13060) --- src/newgrf_industries.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp index bd8fe0084b..41ab0218cc 100644 --- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -404,6 +404,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(uint8_t param_setID, uint8_ case 0xB0: return ClampTo(this->industry->construction_date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // Date when built since 1920 (in days) case 0xB3: return this->industry->construction_type; // Construction type case 0xB4: { + if (this->industry->accepted.empty()) return 0; auto it = std::max_element(std::begin(this->industry->accepted), std::end(this->industry->accepted), [](const auto &a, const auto &b) { return a.last_accepted < b.last_accepted; }); return ClampTo(it->last_accepted - EconomyTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // Date last cargo accepted since 1920 (in days) }