From db735a598ffd5ddb3faccf0412e5069cecefe8ad Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Mon, 22 Oct 2018 05:24:13 +1100 Subject: [PATCH] Fix underflow in shuffle with empty list --- beacon_chain/utils/shuffling/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beacon_chain/utils/shuffling/src/lib.rs b/beacon_chain/utils/shuffling/src/lib.rs index 91a3a73e2..9691240f8 100644 --- a/beacon_chain/utils/shuffling/src/lib.rs +++ b/beacon_chain/utils/shuffling/src/lib.rs @@ -34,7 +34,7 @@ pub fn shuffle( return Ok(list); } - for i in 0..(list.len() - 1) { + for i in 0..(list.len().saturating_sub(1)) { let n = list.len() - i; let j = rng.rand_range(n as u32) as usize + i; list.swap(i, j);