Skip to content

Commit d13f3f2

Browse files
committed
Fix potentially integer overflow
1 parent c7b479d commit d13f3f2

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Diff for: src/searching/binary_search.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub fn binary_search<T: Ord>(item: &T, arr: &[T]) -> Option<usize> {
55
let mut right = arr.len();
66

77
while left < right {
8-
let mid = (left + right) / 2;
8+
let mid = left + (right - left) / 2;
99

1010
match item.cmp(&arr[mid]) {
1111
Ordering::Less => right = mid,

0 commit comments

Comments
 (0)