mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-09 16:37:36 +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,
|
&self,
|
||||||
ptr: Scalar<M::PointerTag>,
|
ptr: Scalar<M::PointerTag>,
|
||||||
size: Size,
|
size: Size,
|
||||||
allow_ptr: bool,
|
allow_ptr_and_undef: bool,
|
||||||
) -> EvalResult<'tcx> {
|
) -> EvalResult<'tcx> {
|
||||||
// Empty accesses don't need to be valid pointers, but they should still be non-NULL
|
// Empty accesses don't need to be valid pointers, but they should still be non-NULL
|
||||||
let align = Align::from_bytes(1, 1).unwrap();
|
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()?;
|
let ptr = ptr.to_ptr()?;
|
||||||
// Check bounds, align and relocations on the edges
|
// Check bounds, align and relocations on the edges
|
||||||
self.get_bytes_with_undef_and_ptr(ptr, size, align)?;
|
self.get_bytes_with_undef_and_ptr(ptr, size, align)?;
|
||||||
// Check undef, and maybe ptr
|
// Check undef and ptr
|
||||||
self.check_defined(ptr, size)?;
|
if !allow_ptr_and_undef {
|
||||||
if !allow_ptr {
|
self.check_defined(ptr, size)?;
|
||||||
self.check_relocations(ptr, size)?;
|
self.check_relocations(ptr, size)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
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
|
// reject it. However, that's good: We don't inherently want
|
||||||
// to reject those pointers, we just do not have the machinery to
|
// to reject those pointers, we just do not have the machinery to
|
||||||
// talk about parts of a pointer.
|
// 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.
|
// In the happy case, we needn't check anything else.
|
||||||
Ok(()) => {},
|
Ok(()) => {},
|
||||||
// Some error happened, try to provide a more detailed description.
|
// Some error happened, try to provide a more detailed description.
|
||||||
|
Loading…
Reference in New Issue
Block a user