From 0b781b04cb1168095807f86e3b0dfadebf3a1ed2 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 20 May 2022 15:55:55 +0200 Subject: [PATCH] Ensure we never consider the null pointer dereferencable --- compiler/rustc_const_eval/src/interpret/memory.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler/rustc_const_eval/src/interpret/memory.rs b/compiler/rustc_const_eval/src/interpret/memory.rs index 33162a01ed201..5dcd209a8fb30 100644 --- a/compiler/rustc_const_eval/src/interpret/memory.rs +++ b/compiler/rustc_const_eval/src/interpret/memory.rs @@ -441,6 +441,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { msg, }) } + // Ensure we never consider the null pointer dereferencable. + if M::PointerTag::OFFSET_IS_ADDR { + assert_ne!(ptr.addr(), Size::ZERO); + } // Test align. Check this last; if both bounds and alignment are violated // we want the error to be about the bounds. if let Some(align) = align {