From 552cf72b9886d76c79adb2e46bf88b70e84b34ee Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Thu, 31 Oct 2024 00:11:16 +0000 Subject: [PATCH] Codefix: Immediately return invalid rail/road type when looking for label 0. (#13045) Looking for label 0 would incorrectly return the first undefined type instead of INVALID_RAIL/ROADTYPE, which could potentially cause incorrect behaviour. --- src/rail.cpp | 2 ++ src/road.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/rail.cpp b/src/rail.cpp index 290248ac88..4419f852fe 100644 --- a/src/rail.cpp +++ b/src/rail.cpp @@ -310,6 +310,8 @@ RailTypes GetRailTypes(bool introduces) */ RailType GetRailTypeByLabel(RailTypeLabel label, bool allow_alternate_labels) { + if (label == 0) return INVALID_RAILTYPE; + /* Loop through each rail type until the label is found */ for (RailType r = RAILTYPE_BEGIN; r != RAILTYPE_END; r++) { const RailTypeInfo *rti = GetRailTypeInfo(r); diff --git a/src/road.cpp b/src/road.cpp index 248533c4fd..f66bedfd65 100644 --- a/src/road.cpp +++ b/src/road.cpp @@ -253,6 +253,8 @@ RoadTypes GetRoadTypes(bool introduces) */ RoadType GetRoadTypeByLabel(RoadTypeLabel label, bool allow_alternate_labels) { + if (label == 0) return INVALID_ROADTYPE; + /* Loop through each road type until the label is found */ for (RoadType r = ROADTYPE_BEGIN; r != ROADTYPE_END; r++) { const RoadTypeInfo *rti = GetRoadTypeInfo(r);