Skip to content

Commit

Permalink
v6: fix panic on new stable (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
leshow authored Jun 6, 2024
1 parent 4b1467d commit 8af42b3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.67.0
1.78.0
2 changes: 1 addition & 1 deletion src/v4/relay.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//!
//! # relay
use std::{collections::HashMap, fmt, net::Ipv4Addr};

use crate::{Decodable, Encodable};
Expand Down
8 changes: 7 additions & 1 deletion src/v6/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ where
let mid = (l + r) >> 1;
// SAFETY: we know it is within the length
let mid_cmp = f(unsafe { arr.get_unchecked(mid) });
let nxt_cmp = if mid < n {
let nxt_cmp = if mid < n && mid != n - 1 {
f(unsafe { arr.get_unchecked(mid + 1) }) == Ordering::Greater
} else {
false
Expand Down Expand Up @@ -991,6 +991,12 @@ mod tests {
let arr = vec![1, 2, 2, 2, 2, 3, 4, 7, 8, 8];
assert_eq!(Some(7..=7), range_binsearch(&arr, |x| x.cmp(&7)));

let arr = vec![1, 2, 2, 2, 2, 3, 4, 7, 8, 9];
assert_eq!(Some(9..=9), range_binsearch(&arr, |x| x.cmp(&9)));

let arr = vec![1, 2, 2, 2, 2, 3, 4, 7, 9, 8];
assert_eq!(Some(0..=0), range_binsearch(&arr, |x| x.cmp(&1)));

let arr: Vec<i32> = vec![];
assert_eq!(None, range_binsearch(&arr, |x| x.cmp(&1)));

Expand Down

0 comments on commit 8af42b3

Please sign in to comment.