Skip to content

Commit 931ebe8

Browse files
authored
Fix bounds checks on binary search (#4577)
1 parent 30cd352 commit 931ebe8

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

Source/Charts/Data/Implementations/Standard/ChartDataSet.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ open class ChartDataSet: ChartBaseDataSet
214214
rounding: ChartDataSetRounding) -> Int
215215
{
216216
var closest = partitioningIndex { $0.x >= xValue }
217-
guard closest < endIndex else { return closest }
217+
guard closest < endIndex else { return -1 }
218218

219219
let closestXValue = self[closest].x
220220

@@ -237,8 +237,6 @@ open class ChartDataSet: ChartBaseDataSet
237237
break
238238
}
239239

240-
guard closest < endIndex else { return endIndex }
241-
242240
// Search by closest to y-value
243241
if !yValue.isNaN
244242
{
@@ -250,7 +248,7 @@ open class ChartDataSet: ChartBaseDataSet
250248
var closestYValue = self[closest].y
251249
var closestYIndex = closest
252250

253-
while closest < endIndex
251+
while closest < index(before: endIndex)
254252
{
255253
formIndex(after: &closest)
256254
let value = self[closest]

0 commit comments

Comments
 (0)