mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 16:18:42 +00:00
Better Bounds Checking in RideFile::intervalBegin()
Return value when out of bounds had a fencepost error. Annoyingly it is exactly the same fencepost error that was fixed in a line of code 10 lines lower in the source. This fixes rare issues with rides where intervals start at the end of the ride file. This can happen with rides that have been split.
This commit is contained in:
committed by
Gareth Coco
parent
b01c007ed2
commit
cd6b86c3eb
@@ -119,8 +119,11 @@ RideFile::intervalBegin(const RideFileInterval &interval) const
|
||||
QVector<RideFilePoint*>::const_iterator i = std::lower_bound(
|
||||
dataPoints_.begin(), dataPoints_.end(), &p, ComparePointSecs());
|
||||
if (i == dataPoints_.end())
|
||||
return dataPoints_.size();
|
||||
return i - dataPoints_.begin();
|
||||
return dataPoints_.size()-1;
|
||||
int offset = i - dataPoints_.begin();
|
||||
if (offset > dataPoints_.size()) return dataPoints_.size()-1;
|
||||
else if (offset <0) return 0;
|
||||
else return offset;
|
||||
}
|
||||
|
||||
double
|
||||
@@ -162,7 +165,7 @@ RideFile::distanceIndex(double km) const
|
||||
QVector<RideFilePoint*>::const_iterator i = std::lower_bound(
|
||||
dataPoints_.begin(), dataPoints_.end(), &p, ComparePointKm());
|
||||
if (i == dataPoints_.end())
|
||||
return dataPoints_.size();
|
||||
return dataPoints_.size()-1;
|
||||
return i - dataPoints_.begin();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user