mirror of https://github.com/OpenTTD/OpenTTD
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.pull/13048/head
parent
9dae626237
commit
552cf72b98
|
@ -310,6 +310,8 @@ RailTypes GetRailTypes(bool introduces)
|
||||||
*/
|
*/
|
||||||
RailType GetRailTypeByLabel(RailTypeLabel label, bool allow_alternate_labels)
|
RailType GetRailTypeByLabel(RailTypeLabel label, bool allow_alternate_labels)
|
||||||
{
|
{
|
||||||
|
if (label == 0) return INVALID_RAILTYPE;
|
||||||
|
|
||||||
/* Loop through each rail type until the label is found */
|
/* Loop through each rail type until the label is found */
|
||||||
for (RailType r = RAILTYPE_BEGIN; r != RAILTYPE_END; r++) {
|
for (RailType r = RAILTYPE_BEGIN; r != RAILTYPE_END; r++) {
|
||||||
const RailTypeInfo *rti = GetRailTypeInfo(r);
|
const RailTypeInfo *rti = GetRailTypeInfo(r);
|
||||||
|
|
|
@ -253,6 +253,8 @@ RoadTypes GetRoadTypes(bool introduces)
|
||||||
*/
|
*/
|
||||||
RoadType GetRoadTypeByLabel(RoadTypeLabel label, bool allow_alternate_labels)
|
RoadType GetRoadTypeByLabel(RoadTypeLabel label, bool allow_alternate_labels)
|
||||||
{
|
{
|
||||||
|
if (label == 0) return INVALID_ROADTYPE;
|
||||||
|
|
||||||
/* Loop through each road type until the label is found */
|
/* Loop through each road type until the label is found */
|
||||||
for (RoadType r = ROADTYPE_BEGIN; r != ROADTYPE_END; r++) {
|
for (RoadType r = ROADTYPE_BEGIN; r != ROADTYPE_END; r++) {
|
||||||
const RoadTypeInfo *rti = GetRoadTypeInfo(r);
|
const RoadTypeInfo *rti = GetRoadTypeInfo(r);
|
||||||
|
|
Loading…
Reference in New Issue