tor-circmgr: random_idx_where: Don't panic on empty range

Fixes #918.
This commit is contained in:
Ian Jackson 2023-06-23 10:59:52 +01:00
parent d1658a120e
commit a0f5dbc05d
1 changed files with 3 additions and 0 deletions

View File

@ -144,6 +144,9 @@ where
P: Fn(&T) -> bool,
{
let n_circuits = slice.len();
if n_circuits == 0 {
return None;
}
let shift = rng.gen_range(0..n_circuits);
(shift..n_circuits)
.chain(0..shift)