Skip to content

Commit e90f51a

Browse files
committed
Remove uses of cast
1 parent 563eac2 commit e90f51a

File tree

7 files changed

+14
-7
lines changed

7 files changed

+14
-7
lines changed

benches/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ fn bench<const N: usize>(b: &mut test::Bencher) {
1515
fn bench_raw<const N: usize>(b: &mut test::Bencher) {
1616
b.iter(|| {
1717
let mut buf = core::mem::MaybeUninit::<[u8; N]>::uninit();
18-
unsafe { getrandom::getrandom_raw(buf.as_mut_ptr().cast(), N).unwrap() };
18+
// TODO: use `cast` on MSRV bump to 1.38
19+
unsafe { getrandom::getrandom_raw(buf.as_mut_ptr() as *mut u8, N).unwrap() };
1920
test::black_box(&buf);
2021
});
2122
b.bytes = N as u64;

src/3ds.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ use crate::util_libc::sys_fill_exact;
1111
use crate::Error;
1212

1313
pub unsafe fn getrandom_inner(dst: *mut u8, len: usize) -> Result<(), Error> {
14-
sys_fill_exact(dst, len, |dst, len| libc::getrandom(dst.cast(), len, 0))
14+
// TODO: use `cast` on MSRV bump to 1.38
15+
sys_fill_exact(dst, len, |dst, len| {
16+
libc::getrandom(dst as *mut c_void, len, 0)
17+
})
1518
}

src/bsd_arandom.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ use core::ptr;
1212

1313
unsafe fn kern_arnd(dst: *mut u8, mut len: usize) -> libc::ssize_t {
1414
static MIB: [libc::c_int; 2] = [libc::CTL_KERN, libc::KERN_ARND];
15+
// TODO: use `cast` on MSRV bump to 1.38
1516
let ret = libc::sysctl(
1617
MIB.as_ptr(),
1718
MIB.len() as libc::c_uint,
18-
dst.cast(),
19+
dst as *mut c_void,
1920
&mut len,
2021
ptr::null(),
2122
0,

src/espidf.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub unsafe fn getrandom_inner(dst: *mut u8, len: usize) -> Result<(), Error> {
2020
// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/random.html
2121
//
2222
// However tracking if some of these entropy sources is enabled is way too difficult to implement here
23-
esp_fill_random(dst.cast(), len);
23+
// TODO: use `cast` on MSRV bump to 1.38
24+
esp_fill_random(dst as *mut c_void, len);
2425
Ok(())
2526
}

src/linux_android.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub unsafe fn getrandom_inner(dst: *mut u8, len: usize) -> Result<(), Error> {
1717
// getrandom(2) was introduced in Linux 3.17
1818
static HAS_GETRANDOM: LazyBool = LazyBool::new();
1919
if HAS_GETRANDOM.unsync_init(is_getrandom_available) {
20-
// TODO: use `cast_mut` on MSRV bump to 1.38
20+
// TODO: use `cast` on MSRV bump to 1.38
2121
sys_fill_exact(dst, len, |dst, len| {
2222
getrandom(dst as *mut libc::c_void, len, 0)
2323
})

src/openbsd.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ pub unsafe fn getrandom_inner(mut dst: *mut u8, mut len: usize) -> Result<(), Er
1313
// getentropy(2) was added in OpenBSD 5.6, so we can use it unconditionally.
1414
while len != 0 {
1515
let chunk_len = core::cmp::min(len, 256);
16-
let ret = libc::getentropy(dst.cast(), chunk_len);
16+
// TODO: use `cast` on MSRV bump to 1.38
17+
let ret = libc::getentropy(dst as *mut c_void, chunk_len);
1718
if ret == -1 {
1819
return Err(last_os_error());
1920
}

src/rdrand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub unsafe fn getrandom_inner(dst: *mut u8, len: usize) -> Result<(), Error> {
8282
#[target_feature(enable = "rdrand")]
8383
unsafe fn rdrand_exact(mut dst: *mut u8, mut len: usize) -> Result<(), Error> {
8484
while len >= WORD_SIZE {
85-
// TODO: use `cast_mut` on MSRV bump to 1.38
85+
// TODO: use `cast` on MSRV bump to 1.38
8686
ptr::write(dst as *mut [u8; WORD_SIZE], rdrand()?);
8787
dst = dst.add(WORD_SIZE);
8888
len -= WORD_SIZE;

0 commit comments

Comments
 (0)