From 05c0542d1fa691698e811fc200e802156e70d5b2 Mon Sep 17 00:00:00 2001 From: John Kastner Date: Sat, 2 Mar 2024 15:00:13 -0500 Subject: [PATCH] Fix off-by-one error in assertions (#21509) These should assert that the index in within the bounds of the array, but it asserts that it is in [0, size] (inclusive). Adjust the assertion so they fail for an access at `size`. --- src/openrct2/rct1/Tables.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/openrct2/rct1/Tables.cpp b/src/openrct2/rct1/Tables.cpp index c6e6158ff4..4a7bc17109 100644 --- a/src/openrct2/rct1/Tables.cpp +++ b/src/openrct2/rct1/Tables.cpp @@ -260,7 +260,7 @@ namespace RCT1 }; const auto index = EnumValue(rideType); - Guard::ArgumentInRange(index, 0, std::size(map), "Unsupported RCT1 ride type."); + Guard::ArgumentInRange(index, 0, std::size(map) - 1, "Unsupported RCT1 ride type."); return map[index]; } @@ -360,7 +360,7 @@ namespace RCT1 { COPY_COLOUR_1, COPY_COLOUR_2, COLOUR_BLACK }, // RCT1_VEHICLE_TYPE_ENTERPRISE_WHEEL }; - Guard::ArgumentInRange(EnumValue(vehicleType), 0, std::size(map), "Unsupported RCT1 vehicle type."); + Guard::ArgumentInRange(EnumValue(vehicleType), 0, std::size(map) - 1, "Unsupported RCT1 vehicle type."); return map[EnumValue(vehicleType)]; } @@ -792,7 +792,7 @@ namespace RCT1 }; const auto index = EnumValue(rideType); - Guard::ArgumentInRange(index, 0, std::size(map), "Unsupported RCT1 ride type."); + Guard::ArgumentInRange(index, 0, std::size(map) - 1, "Unsupported RCT1 ride type."); return map[index]; } @@ -892,7 +892,7 @@ namespace RCT1 "rct2.ride.enterp", // VehicleType::EnterpriseWheel }; - Guard::ArgumentInRange(EnumValue(vehicleType), 0, std::size(map), "Unsupported RCT1 vehicle type."); + Guard::ArgumentInRange(EnumValue(vehicleType), 0, std::size(map) - 1, "Unsupported RCT1 vehicle type."); return map[EnumValue(vehicleType)]; }