@@ -484,8 +484,7 @@ impl<T: ?Sized> *mut T {
484
484
// Else if count is not zero, then ensure that subtracting `count` doesn't
485
485
// cause overflow and that both pointers `self` and the result are in the
486
486
// same allocation
487
- ( mem:: size_of_val_raw( self ) != 0 &&
488
- ( self . addr( ) as isize ) . checked_add( count) . is_some( ) &&
487
+ ( ( self . addr( ) as isize ) . checked_add( count) . is_some( ) &&
489
488
kani:: mem:: same_allocation( self , self . wrapping_byte_offset( count) ) )
490
489
) ]
491
490
#[ ensures( |& result|
@@ -1111,8 +1110,7 @@ impl<T: ?Sized> *mut T {
1111
1110
// Else if count is not zero, then ensure that subtracting `count` doesn't
1112
1111
// cause overflow and that both pointers `self` and the result are in the
1113
1112
// same allocation
1114
- ( mem:: size_of_val_raw( self ) != 0 &&
1115
- ( self . addr( ) as isize ) . checked_add( count as isize ) . is_some( ) &&
1113
+ ( ( self . addr( ) as isize ) . checked_add( count as isize ) . is_some( ) &&
1116
1114
kani:: mem:: same_allocation( self , self . wrapping_byte_add( count) ) )
1117
1115
) ]
1118
1116
#[ ensures( |& result|
@@ -1258,8 +1256,7 @@ impl<T: ?Sized> *mut T {
1258
1256
// Else if count is not zero, then ensure that subtracting `count` doesn't
1259
1257
// cause overflow and that both pointers `self` and the result are in the
1260
1258
// same allocation
1261
- ( mem:: size_of_val_raw( self ) != 0 &&
1262
- ( self . addr( ) as isize ) . checked_sub( count as isize ) . is_some( ) &&
1259
+ ( ( self . addr( ) as isize ) . checked_sub( count as isize ) . is_some( ) &&
1263
1260
kani:: mem:: same_allocation( self , self . wrapping_byte_sub( count) ) )
1264
1261
) ]
1265
1262
#[ ensures( |& result|
@@ -2410,6 +2407,31 @@ mod verify {
2410
2407
use core:: mem;
2411
2408
use kani:: PointerGenerator ;
2412
2409
2410
+ // bounding space for PointerGenerator to accommodate 40 elements.
2411
+ const ARRAY_LEN : usize = 40 ;
2412
+
2413
+ #[ kani:: proof_for_contract( <* mut ( ) >:: byte_offset) ]
2414
+ #[ kani:: should_panic]
2415
+ pub fn check_mut_byte_offset_unit_invalid_count ( ) {
2416
+ let mut val = ( ) ;
2417
+ let ptr: * mut ( ) = & mut val;
2418
+ let count: isize = kani:: any_where ( |& x| x > ( mem:: size_of :: < ( ) > ( ) as isize ) ) ;
2419
+ unsafe {
2420
+ ptr. byte_offset ( count) ;
2421
+ }
2422
+ }
2423
+
2424
+ #[ kani:: proof_for_contract( <* mut ( ) >:: byte_offset) ]
2425
+ pub fn check_mut_byte_offset_cast_unit ( ) {
2426
+ let mut generator = PointerGenerator :: < ARRAY_LEN > :: new ( ) ;
2427
+ let ptr: * mut u8 = generator. any_in_bounds ( ) . ptr ;
2428
+ let ptr1: * mut ( ) = ptr as * mut ( ) ;
2429
+ let count: isize = kani:: any ( ) ;
2430
+ unsafe {
2431
+ ptr1. byte_offset ( count) ;
2432
+ }
2433
+ }
2434
+
2413
2435
// generate proof for contracts of byte_add, byte_sub and byte_offset to verify
2414
2436
// unit pointee type
2415
2437
// - `$fn_name`: function for which the contract must be verified
@@ -2420,7 +2442,7 @@ mod verify {
2420
2442
pub fn $proof_name( ) {
2421
2443
let mut val = ( ) ;
2422
2444
let ptr: * mut ( ) = & mut val;
2423
- let count: isize = kani :: any ( ) ;
2445
+ let count: isize = mem :: size_of :: < ( ) > ( ) as isize ;
2424
2446
unsafe {
2425
2447
ptr. byte_offset( count) ;
2426
2448
}
@@ -2433,7 +2455,7 @@ mod verify {
2433
2455
let mut val = ( ) ;
2434
2456
let ptr: * mut ( ) = & mut val;
2435
2457
//byte_add and byte_sub need count to be usize unlike byte_offset
2436
- let count: usize = kani :: any ( ) ;
2458
+ let count: usize = mem :: size_of :: < ( ) > ( ) ;
2437
2459
unsafe {
2438
2460
ptr. $fn_name( count) ;
2439
2461
}
@@ -2445,9 +2467,6 @@ mod verify {
2445
2467
gen_mut_byte_arith_harness_for_unit ! ( byte_sub, check_mut_byte_sub_unit) ;
2446
2468
gen_mut_byte_arith_harness_for_unit ! ( byte_offset, check_mut_byte_offset_unit) ;
2447
2469
2448
- // bounding space for PointerGenerator to accommodate 40 elements.
2449
- const ARRAY_LEN : usize = 40 ;
2450
-
2451
2470
// generate proof for contracts for byte_add, byte_sub and byte_offset
2452
2471
// - `$type`: pointee type
2453
2472
// - `$fn_name`: function for which the contract must be verified
0 commit comments