@@ -241,7 +241,7 @@ pub extern "C" fn rust_util_bytes(buf: *const c_uchar, len: usize) -> Bytes {
241
241
/// * `buf` - Must be a valid pointer to an array of bytes
242
242
/// * `len` - Length of buffer, `buf[len-1]` must be a valid dereference
243
243
#[ no_mangle]
244
- pub extern "C" fn rust_util_bytes_mut ( buf : * mut c_uchar , len : usize ) -> BytesMut {
244
+ pub unsafe extern "C" fn rust_util_bytes_mut ( buf : * mut c_uchar , len : usize ) -> BytesMut {
245
245
BytesMut { buf, len }
246
246
}
247
247
@@ -286,19 +286,19 @@ mod tests {
286
286
#[ test]
287
287
fn zeroing ( ) {
288
288
let mut buf = [ 1u8 , 2 , 3 , 4 ] ;
289
- rust_util_zero ( rust_util_bytes_mut ( buf. as_mut_ptr ( ) , buf. len ( ) - 1 ) ) ;
289
+ rust_util_zero ( unsafe { rust_util_bytes_mut ( buf. as_mut_ptr ( ) , buf. len ( ) - 1 ) } ) ;
290
290
assert_eq ! ( & buf[ ..] , & [ 0 , 0 , 0 , 4 ] ) ;
291
291
}
292
292
293
293
#[ test]
294
294
fn zeroing_empty ( ) {
295
295
let mut buf = [ ] ;
296
- rust_util_zero ( rust_util_bytes_mut ( buf. as_mut_ptr ( ) , 0 ) ) ;
296
+ rust_util_zero ( unsafe { rust_util_bytes_mut ( buf. as_mut_ptr ( ) , 0 ) } ) ;
297
297
}
298
298
299
299
#[ test]
300
300
fn zeroing_null ( ) {
301
- rust_util_zero ( rust_util_bytes_mut ( core:: ptr:: null_mut ( ) , 0 ) ) ;
301
+ rust_util_zero ( unsafe { rust_util_bytes_mut ( core:: ptr:: null_mut ( ) , 0 ) } ) ;
302
302
}
303
303
304
304
#[ test]
@@ -316,7 +316,9 @@ mod tests {
316
316
#[ should_panic]
317
317
fn create_invalid_bytes_mut ( ) {
318
318
// Calling `as_mut()` will panic because it tries to create an invalid rust slice.
319
- rust_util_bytes_mut ( core:: ptr:: null_mut ( ) , 1 ) . as_mut ( ) ;
319
+ unsafe {
320
+ rust_util_bytes_mut ( core:: ptr:: null_mut ( ) , 1 ) . as_mut ( ) ;
321
+ }
320
322
}
321
323
322
324
#[ test]
0 commit comments