@@ -1820,21 +1820,18 @@ mod verify {
1820
1820
let result = nonnull_ptr_u8. read ( ) ;
1821
1821
kani:: assert ( * ptr_u8 == result, "read returns the correct value" ) ;
1822
1822
}
1823
- /*
1823
+
1824
+ // array example
1824
1825
const arr_len: usize = 10 ;
1825
1826
let offset = kani:: any_where ( |x| * x < arr_len) ;
1826
1827
kani:: assume ( offset >= 0 ) ;
1827
1828
let arr: [ i8 ; arr_len] = kani:: any ( ) ;
1828
1829
let raw_ptr: * mut i8 = arr. as_ptr ( ) as * mut i8 ;
1829
- let nonnull_ptr = unsafe { NonNull::new(raw_ptr.add(offset)).unwrap()};
1830
- let slice_len = arr_len - offset;
1831
- let slice_ptr = NonNull::slice_from_raw_parts(nonnull_ptr, slice_len);
1830
+ let nonnull_ptr = unsafe { NonNull :: new ( raw_ptr) . unwrap ( ) } ;
1832
1831
unsafe {
1833
- let result = slice_ptr. read(); //TODO: slice is unsized and cannot call read
1834
- kani::assert(*nonnull_ptr.pointer == result, "read returns the correct value");
1832
+ let result = nonnull_ptr . add ( offset ) . read ( ) ;
1833
+ kani:: assert ( * nonnull_ptr. as_ptr ( ) . add ( offset ) == result, "read returns the correct value" ) ;
1835
1834
}
1836
- kani::assert(slice_ptr.as_ref().len() == slice_len, "read preserves slice length");
1837
- */
1838
1835
}
1839
1836
1840
1837
// pub unsafe fn read_volatile(self) -> T where T: Sized
@@ -1867,7 +1864,18 @@ mod verify {
1867
1864
let nonnull_ptr = NonNull :: new ( unaligned_ptr as * mut usize ) . unwrap ( ) ;
1868
1865
unsafe {
1869
1866
let result = nonnull_ptr. read_unaligned ( ) ;
1870
- // TODO: check result matches expectation(how to?)
1867
+ /*
1868
+ let raw_result_ptr = result as *const u8;
1869
+ let raw_original_ptr = &arr[offset] as *const u8;
1870
+ for i in 0..core::mem::size_of::<usize>() {
1871
+ unsafe {
1872
+ // Dereference and compare each byte
1873
+ assert_eq!(*raw_original_ptr.add(i), *raw_result_ptr.add(i));
1874
+ }
1875
+
1876
+ }
1877
+ // TODO: check result matches expectation(how to?) compare slice of bytes
1878
+ */
1871
1879
}
1872
1880
1873
1881
// read an unaligned value from a packed struct
0 commit comments