17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-28 21:37:31 +01:00

fix(ai): keep the light selector lookup within its table, Sonar findings of the handover

- the light selector size comes from the vehicle definition (LightsList Size)
  and isn't limited, while the table holds 18 positions; a bigger selector
  read past the table, and so did a table index other than the front or
  rear one. Only the positions the table holds are looked at now, and the
  selector stays where it is for a bad table index (cpp:S2259),
- the lambdas of the handover capture what they use explicitly (cpp:S3608),
- the chained assignments resetting the headlight state on the AI taking
  over are split (cpp:S1121).
This commit is contained in:
jerrrrycho
2026-10-15 21:28:20 +02:00
parent 54990f41a6
commit 7727748b76
3 changed files with 30 additions and 7 deletions

View File

@@ -109,6 +109,24 @@ TEST_CASE("handover: the light selector moves to the position giving the head li
}
}
TEST_CASE("handover: the light selector stays within its table") {
auto cab{cab_vehicle()};
SUBCASE("selector bigger than the table, as a vehicle definition can declare") {
// only the positions the table holds are looked at, the rest can't match
for (auto &table : cab->Lights) {
std::fill(std::begin(table) + cab->LightsPosNo, std::end(table), 0);
}
cab->LightsPosNo = 100;
CHECK(handover::light_selector_position(cab.mover(), end::front, pc1, allheadlights) == 2);
CHECK(handover::light_selector_position(cab.mover(), end::front, light::headlight_left, allheadlights) == 1);
}
SUBCASE("table other than the front or rear one: the selector stays") {
CHECK(handover::light_selector_position(cab.mover(), -1, pc1, allheadlights) == 1);
CHECK(handover::light_selector_position(cab.mover(), 2, pc1, allheadlights) == 1);
}
}
TEST_CASE("handover: the light selector already matching the lights stays") {
auto cab{cab_vehicle()};
cab->LightsPos = 2; // Pc1