From 2a7e74d0340cdedbccbfaf6fa9694a2d29bebb10 Mon Sep 17 00:00:00 2001 From: Elichai Turkel Date: Mon, 16 Sep 2019 21:40:42 +0300 Subject: [PATCH 1/2] Handle ZST --- src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 023a6230..e58f58c2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -266,5 +266,8 @@ cfg_if! { /// significantly slower than a user-space CSPRNG; for the latter consider /// [`rand::thread_rng`](https://docs.rs/rand/*/rand/fn.thread_rng.html). pub fn getrandom(dest: &mut [u8]) -> Result<(), error::Error> { + if dest.is_empty() { + return Ok(()) + } imp::getrandom_inner(dest) } From d68b942199ebd471025c1615eb22f76d63abbb66 Mon Sep 17 00:00:00 2001 From: Joe Richey Date: Thu, 19 Sep 2019 16:05:40 -0700 Subject: [PATCH 2/2] Add empty slice documentation --- src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index e58f58c2..421cf4cb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -258,7 +258,9 @@ cfg_if! { /// source. /// /// This function returns an error on any failure, including partial reads. We -/// make no guarantees regarding the contents of `dest` on error. +/// make no guarantees regarding the contents of `dest` on error. If `dest` is +/// empty, `getrandom` immediately returns success, making no calls to the +/// underlying operating system. /// /// Blocking is possible, at least during early boot; see module documentation. ///