mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-09 00:17:44 +00:00
run-time validation: accept undef in int arrays, as we do for ints
This commit is contained in:
parent
b2ddd27c2e
commit
06a4911ce1
@ -846,7 +846,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
|
||||
&self,
|
||||
ptr: Scalar<M::PointerTag>,
|
||||
size: Size,
|
||||
allow_ptr: bool,
|
||||
allow_ptr_and_undef: bool,
|
||||
) -> EvalResult<'tcx> {
|
||||
// Empty accesses don't need to be valid pointers, but they should still be non-NULL
|
||||
let align = Align::from_bytes(1, 1).unwrap();
|
||||
@ -857,9 +857,9 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
|
||||
let ptr = ptr.to_ptr()?;
|
||||
// Check bounds, align and relocations on the edges
|
||||
self.get_bytes_with_undef_and_ptr(ptr, size, align)?;
|
||||
// Check undef, and maybe ptr
|
||||
self.check_defined(ptr, size)?;
|
||||
if !allow_ptr {
|
||||
// Check undef and ptr
|
||||
if !allow_ptr_and_undef {
|
||||
self.check_defined(ptr, size)?;
|
||||
self.check_relocations(ptr, size)?;
|
||||
}
|
||||
Ok(())
|
||||
|
@ -517,7 +517,12 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
|
||||
// reject it. However, that's good: We don't inherently want
|
||||
// to reject those pointers, we just do not have the machinery to
|
||||
// talk about parts of a pointer.
|
||||
match self.memory.check_bytes(dest.ptr, size, /*allow_ptr*/!const_mode) {
|
||||
// We also accept undef, for consistency with the type-based checks.
|
||||
match self.memory.check_bytes(
|
||||
dest.ptr,
|
||||
size,
|
||||
/*allow_ptr_and_undef*/!const_mode,
|
||||
) {
|
||||
// In the happy case, we needn't check anything else.
|
||||
Ok(()) => {},
|
||||
// Some error happened, try to provide a more detailed description.
|
||||
|
Loading…
Reference in New Issue
Block a user