Skip to content

Commit 207ac4c

Browse files
committed
Add back empty slice check
#291 inadvertantly removed this check See #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>
1 parent 47a59dd commit 207ac4c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,9 @@ pub fn getrandom(dest: &mut [u8]) -> Result<(), Error> {
322322
/// ```
323323
#[inline]
324324
pub fn getrandom_uninit(dest: &mut [MaybeUninit<u8>]) -> Result<&mut [u8], Error> {
325-
imp::getrandom_inner(dest)?;
325+
if !dest.is_empty() {
326+
imp::getrandom_inner(dest)?;
327+
}
326328
// SAFETY: `dest` has been fully initialized by `imp::getrandom_inner`
327329
// since it returned `Ok`.
328330
Ok(unsafe { slice_assume_init_mut(dest) })

0 commit comments

Comments
 (0)