Add back empty slice check (#298)

https://github.com/rust-random/getrandom/pull/291 inadvertantly removed
this check

See https://github.com/rust-random/getrandom/pull/104 for why this was
added in the first place. Also, per our docs:

> If `dest` is empty, `getrandom` immediately returns success, making
> no calls to the underlying operating system.

Signed-off-by: Joe Richey <joerichey@google.com>
This commit is contained in:
Joseph Richey 2022-10-21 07:02:34 -07:00 committed by GitHub
parent 47a59dda25
commit 55ad4c41ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -322,7 +322,9 @@ pub fn getrandom(dest: &mut [u8]) -> Result<(), Error> {
/// ```
#[inline]
pub fn getrandom_uninit(dest: &mut [MaybeUninit<u8>]) -> Result<&mut [u8], Error> {
if !dest.is_empty() {
imp::getrandom_inner(dest)?;
}
// SAFETY: `dest` has been fully initialized by `imp::getrandom_inner`
// since it returned `Ok`.
Ok(unsafe { slice_assume_init_mut(dest) })