If an extern C function is defined as
```
extern "C" {
fn malloc(size: u32) -> *mut std::ffi::c_void;
}
```
on a 64-bit machine(ie. pointer sizes don't match), throw an undefined
behaviour.
InvalidUndefBytes(Option<Pointer>),
/// Working with a local that is not currently live.
DeadLocal,
+ /// Data size is not equal to target size
+ ArgumentSizeMismatch {
+ target_size: u64,
+ data_size: u64,
+ },
}
impl fmt::Debug for UndefinedBehaviorInfo {
"using uninitialized data, but this operation requires initialized memory"
),
DeadLocal => write!(f, "accessing a dead local variable"),
+ ArgumentSizeMismatch { target_size, data_size } => write!(
+ f,
+ "argument size mismatch: expected {} bytes but got {} bytes instead",
+ target_size, data_size
+ ),
}
}
}
assert_ne!(target_size.bytes(), 0, "you should never look at the bits of a ZST");
match self {
Scalar::Raw { data, size } => {
- assert_eq!(target_size.bytes(), u64::from(size));
+ if target_size.bytes() != u64::from(size) {
+ throw_ub!(ArgumentSizeMismatch {
+ target_size: target_size.bytes(),
+ data_size: u64::from(size)
+ });
+ }
Scalar::check_data(data, size);
Ok(data)
}