Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1730,15 +1730,20 @@ impl GotocCtx<'_> {

// Check that computing `count` in bytes would not overflow
let (count_bytes, overflow_check) = self.count_in_bytes(
count,
count.clone(),
pointee_type_stable(dst_typ).unwrap(),
Type::size_t(),
"write_bytes",
loc,
);

let memset_call = BuiltinFn::Memset.call(vec![dst, val, count_bytes], loc);
Stmt::block(vec![align_check, overflow_check, memset_call.as_stmt(loc)], loc)
Stmt::if_then_else(
count.clone().gt(Expr::int_constant(0, count.typ().clone())),
Stmt::block(vec![align_check, overflow_check, memset_call.as_stmt(loc)], loc),
None,
loc,
)
}

/// Computes (multiplies) the equivalent of a memory-related number (e.g., an offset) in bytes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,20 @@ fn main() {
assert!(_buf2[idx] == elt);
}
}

#[kani::proof]
fn minimal1() {
let v: Vec<i8> = vec![kani::any(); 0];
}

#[kani::proof]
fn minimal2() {
let v: Vec<i8> = vec![5; 0];
}

#[kani::proof]
fn vec3772() {
let value: u8 = 1; /* set to zero and it passes */
let count: u16 = kani::any();
let vector: Vec<u8> = vec![value; count as usize];
}
Loading