Skip to content

Commit 06a4911

Browse files
committed
run-time validation: accept undef in int arrays, as we do for ints
1 parent b2ddd27 commit 06a4911

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/librustc_mir/interpret/memory.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
846846
&self,
847847
ptr: Scalar<M::PointerTag>,
848848
size: Size,
849-
allow_ptr: bool,
849+
allow_ptr_and_undef: bool,
850850
) -> EvalResult<'tcx> {
851851
// Empty accesses don't need to be valid pointers, but they should still be non-NULL
852852
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> {
857857
let ptr = ptr.to_ptr()?;
858858
// Check bounds, align and relocations on the edges
859859
self.get_bytes_with_undef_and_ptr(ptr, size, align)?;
860-
// Check undef, and maybe ptr
861-
self.check_defined(ptr, size)?;
862-
if !allow_ptr {
860+
// Check undef and ptr
861+
if !allow_ptr_and_undef {
862+
self.check_defined(ptr, size)?;
863863
self.check_relocations(ptr, size)?;
864864
}
865865
Ok(())

src/librustc_mir/interpret/validity.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,12 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
517517
// reject it. However, that's good: We don't inherently want
518518
// to reject those pointers, we just do not have the machinery to
519519
// talk about parts of a pointer.
520-
match self.memory.check_bytes(dest.ptr, size, /*allow_ptr*/!const_mode) {
520+
// We also accept undef, for consistency with the type-based checks.
521+
match self.memory.check_bytes(
522+
dest.ptr,
523+
size,
524+
/*allow_ptr_and_undef*/!const_mode,
525+
) {
521526
// In the happy case, we needn't check anything else.
522527
Ok(()) => {},
523528
// Some error happened, try to provide a more detailed description.

0 commit comments

Comments
 (0)