1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2025-12-10 06:52:05 +01:00

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.
This commit is contained in:
Peter Nelson
2024-10-31 00:11:16 +00:00
committed by GitHub
parent 9dae626237
commit 552cf72b98
2 changed files with 4 additions and 0 deletions

View File

@@ -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);

View File

@@ -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);