Skip to content

Commit

Permalink
Fix bounds checks on binary search (ChartsOrg#4577)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjatie authored and abhiramvadlapatla committed Dec 21, 2021
1 parent c9aa70d commit 2c9a672
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ open class ChartDataSet: ChartBaseDataSet
rounding: ChartDataSetRounding) -> Int
{
var closest = partitioningIndex { $0.x >= xValue }
guard closest < endIndex else { return closest }
guard closest < endIndex else { return -1 }

let closestXValue = self[closest].x

Expand All @@ -237,8 +237,6 @@ open class ChartDataSet: ChartBaseDataSet
break
}

guard closest < endIndex else { return endIndex }

// Search by closest to y-value
if !yValue.isNaN
{
Expand All @@ -250,7 +248,7 @@ open class ChartDataSet: ChartBaseDataSet
var closestYValue = self[closest].y
var closestYIndex = closest

while closest < endIndex
while closest < index(before: endIndex)
{
formIndex(after: &closest)
let value = self[closest]
Expand Down

0 comments on commit 2c9a672

Please sign in to comment.