fix null pointer error messages
This commit is contained in:
parent
ac888e8675
commit
4dddc3818e
3 changed files with 13 additions and 10 deletions
|
@ -170,22 +170,25 @@ impl fmt::Display for InvalidProgramInfo<'_> {
|
||||||
/// Details of why a pointer had to be in-bounds.
|
/// Details of why a pointer had to be in-bounds.
|
||||||
#[derive(Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)]
|
#[derive(Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)]
|
||||||
pub enum CheckInAllocMsg {
|
pub enum CheckInAllocMsg {
|
||||||
|
/// We are access memory.
|
||||||
MemoryAccessTest,
|
MemoryAccessTest,
|
||||||
|
/// We are doing pointer arithmetic.
|
||||||
PointerArithmeticTest,
|
PointerArithmeticTest,
|
||||||
|
/// None of the above -- generic/unspecific inbounds test.
|
||||||
InboundsTest,
|
InboundsTest,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for CheckInAllocMsg {
|
impl fmt::Display for CheckInAllocMsg {
|
||||||
/// When this is printed as an error the context looks like this
|
/// When this is printed as an error the context looks like this
|
||||||
/// "{test name} failed: pointer must be in-bounds at offset..."
|
/// "{msg}pointer must be in-bounds at offset..."
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"{}",
|
"{}",
|
||||||
match *self {
|
match *self {
|
||||||
CheckInAllocMsg::MemoryAccessTest => "memory access",
|
CheckInAllocMsg::MemoryAccessTest => "memory access failed: ",
|
||||||
CheckInAllocMsg::PointerArithmeticTest => "pointer arithmetic",
|
CheckInAllocMsg::PointerArithmeticTest => "pointer arithmetic failed: ",
|
||||||
CheckInAllocMsg::InboundsTest => "inbounds test",
|
CheckInAllocMsg::InboundsTest => "",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -299,18 +302,18 @@ impl fmt::Display for UndefinedBehaviorInfo<'_> {
|
||||||
}
|
}
|
||||||
PointerOutOfBounds { ptr, msg, allocation_size } => write!(
|
PointerOutOfBounds { ptr, msg, allocation_size } => write!(
|
||||||
f,
|
f,
|
||||||
"{} failed: pointer must be in-bounds at offset {}, \
|
"{}pointer must be in-bounds at offset {}, \
|
||||||
but is outside bounds of {} which has size {}",
|
but is outside bounds of {} which has size {}",
|
||||||
msg,
|
msg,
|
||||||
ptr.offset.bytes(),
|
ptr.offset.bytes(),
|
||||||
ptr.alloc_id,
|
ptr.alloc_id,
|
||||||
allocation_size.bytes()
|
allocation_size.bytes()
|
||||||
),
|
),
|
||||||
DanglingIntPointer(_, CheckInAllocMsg::InboundsTest) => {
|
DanglingIntPointer(0, CheckInAllocMsg::InboundsTest) => {
|
||||||
write!(f, "null pointer is not allowed for this operation")
|
write!(f, "null pointer is not a valid pointer for this operation")
|
||||||
}
|
}
|
||||||
DanglingIntPointer(i, msg) => {
|
DanglingIntPointer(i, msg) => {
|
||||||
write!(f, "{} failed: 0x{:x} is not a valid pointer", msg, i)
|
write!(f, "{}0x{:x} is not a valid pointer", msg, i)
|
||||||
}
|
}
|
||||||
AlignmentCheckFailed { required, has } => write!(
|
AlignmentCheckFailed { required, has } => write!(
|
||||||
f,
|
f,
|
||||||
|
|
|
@ -296,7 +296,7 @@ error[E0080]: could not evaluate static initializer
|
||||||
--> $DIR/ub-wide-ptr.rs:135:5
|
--> $DIR/ub-wide-ptr.rs:135:5
|
||||||
|
|
|
|
||||||
LL | mem::transmute::<_, &dyn Trait>((&92u8, 0usize))
|
LL | mem::transmute::<_, &dyn Trait>((&92u8, 0usize))
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ null pointer is not allowed for this operation
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ null pointer is not a valid pointer for this operation
|
||||||
|
|
||||||
error[E0080]: could not evaluate static initializer
|
error[E0080]: could not evaluate static initializer
|
||||||
--> $DIR/ub-wide-ptr.rs:139:5
|
--> $DIR/ub-wide-ptr.rs:139:5
|
||||||
|
|
|
@ -74,7 +74,7 @@ error: any use of this value will cause an error
|
||||||
LL | unsafe { intrinsics::ptr_offset_from(self, origin) }
|
LL | unsafe { intrinsics::ptr_offset_from(self, origin) }
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
| |
|
| |
|
||||||
| null pointer is not allowed for this operation
|
| null pointer is not a valid pointer for this operation
|
||||||
| inside `ptr::const_ptr::<impl *const u8>::offset_from` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
| inside `ptr::const_ptr::<impl *const u8>::offset_from` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
| inside `OFFSET_FROM_NULL` at $DIR/offset_from_ub.rs:36:14
|
| inside `OFFSET_FROM_NULL` at $DIR/offset_from_ub.rs:36:14
|
||||||
|
|
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue