Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bounds checks on binary search #4577

Merged
merged 1 commit into from
Feb 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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