diff options
| author | Botahamec <botahamec@outlook.com> | 2024-09-25 20:38:50 -0400 |
|---|---|---|
| committer | Botahamec <botahamec@outlook.com> | 2024-09-25 20:38:50 -0400 |
| commit | c12df09eff1ada614ce5618eb2d050046bc87419 (patch) | |
| tree | a0f54b58eae6b93c83ffeec23d6aeba2a49c7976 /src/collection | |
| parent | bd64ff98530ea5f92ce528009d65203f0f6676fe (diff) | |
Fix panic in contains_duplicates
Diffstat (limited to 'src/collection')
| -rw-r--r-- | src/collection/boxed.rs | 4 | ||||
| -rw-r--r-- | src/collection/ref.rs | 5 |
2 files changed, 9 insertions, 0 deletions
diff --git a/src/collection/boxed.rs b/src/collection/boxed.rs index 1f068ec..f8e0fb8 100644 --- a/src/collection/boxed.rs +++ b/src/collection/boxed.rs @@ -11,6 +11,10 @@ use super::{utils, BoxedLockCollection, LockGuard}; /// returns `true` if the sorted list contains a duplicate #[must_use] fn contains_duplicates(l: &[&dyn RawLock]) -> bool { + if l.is_empty() { + return false; + } + l.windows(2) .any(|window| std::ptr::eq(window[0], window[1])) } diff --git a/src/collection/ref.rs b/src/collection/ref.rs index c3a0967..8b9e0f8 100644 --- a/src/collection/ref.rs +++ b/src/collection/ref.rs @@ -17,6 +17,11 @@ pub fn get_locks<L: Lockable>(data: &L) -> Vec<&dyn RawLock> { /// returns `true` if the sorted list contains a duplicate #[must_use] fn contains_duplicates(l: &[&dyn RawLock]) -> bool { + if l.is_empty() { + // Return early to prevent panic in the below call to `windows` + return false; + } + l.windows(2) .any(|window| std::ptr::eq(window[0], window[1])) } |
