You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Modifies clauses: an empty slice with a dangling data pointer fails ptr NULL or writable up to size #4931
with Kani version: 0.68.0, built from source at 7207ac1 (current main); CBMC 6.11.0; Arch Linux x86_64.
I expected to see this happen: both harnesses verify. An empty slice covers no memory, so naming it in a modifies clause should be harmless.
Instead, this happened: both fail when the slice is empty:
Checking harness modifies_empty_vec...
Failed Checks: ptr NULL or writable up to size
VERIFICATION:- FAILED
Checking harness loop_modifies_empty_vec...
Failed Checks: ptr NULL or writable up to size
VERIFICATION:- FAILED
The same happens for a slice over the buffer of a String without capacity (slice_from_raw_parts_mut(st.as_mut_ptr(), st.capacity()), which also fails assertion havoc_slice W_OK(car.lb, car.size) in a loop) and for &mut a[..] with a: [u8; 0] (which also fails no offset bits overflow on CAR upper bound computation). An empty slice at the end of a live array (&mut a[4..] with a: [u8; 4]) works.
Cause: a slice target is generated as __CPROVER_object_upto(data, len * size_of::<T>()) (ty_to_assign_target in statement.rs for loops, codegen_modifies_contract in contract.rs for functions). CBMC's __CPROVER_contracts_car_create / __CPROVER_contracts_car_set_insert assert ptr == NULL || __CPROVER_rw_ok(ptr, size), and __CPROVER_rw_ok is false for a dangling pointer even when size is 0. The data pointer of an empty Vec, of a String without capacity or of an empty array is dangling.
This is similar to #3181 and #4786, which were about zero-sized types rather than zero-length slices.
Activity
Use a null pointer for zero-sized slice targets of modifies clauses (m…