mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-28 22:03:20 +01:00
fix(timetable): read the table from its start, bound the station index both ways
read_timetable() went on from the StationCount it was given and checked only the upper bound, so TimeTable[StationCount] and TimeTable[StationCount - 1] could index out of the table (Sonar cpp:S3519). It now resets the count and the table first, and checks both bounds before the next station.
This commit is contained in:
@@ -58,6 +58,9 @@ int read_timetable(std::istream &fin, timetable_data &Data) {
|
||||
int conversionerror{0};
|
||||
auto &TimeTable{Data.TimeTable};
|
||||
auto &StationCount{Data.StationCount};
|
||||
// the table is read from its start, whatever Data held before
|
||||
StationCount = 0;
|
||||
TimeTable.fill(TMTableEntry{});
|
||||
// zapisywanie prędkości maksymalnej do wcześniejszych odcinków
|
||||
auto const UpdateVelocity{[&TimeTable, &StationCount](double const Velocity) {
|
||||
int i = StationCount;
|
||||
@@ -164,12 +167,12 @@ int read_timetable(std::istream &fin, timetable_data &Data) {
|
||||
TimeTable[0].flags = Data.Flags;
|
||||
auto activeradiochannel{-1};
|
||||
while (!fin.fail() && !EndTable) {
|
||||
++StationCount;
|
||||
if (StationCount > MaxTTableSize) {
|
||||
--StationCount;
|
||||
// both bounds, so TimeTable[StationCount] and TimeTable[StationCount - 1] below stay in the table
|
||||
if (StationCount < 0 || StationCount >= MaxTTableSize) {
|
||||
conversionerror = timetable_too_long;
|
||||
break;
|
||||
}
|
||||
++StationCount;
|
||||
do {
|
||||
fin >> s;
|
||||
} while (!(s == "[" || fin.fail()));
|
||||
|
||||
Reference in New Issue
Block a user