Skip to content

Commit 1e38870

Browse files
committed
Add special behaviour when int is zero
1 parent c5c06a5 commit 1e38870

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Diff for: src/librustc_mir/interpret/machine.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,14 @@ pub trait Machine<'mir, 'tcx>: Sized {
211211
) -> InterpResult<'tcx>;
212212

213213
fn int_to_ptr(
214-
_int: u64,
214+
int: u64,
215215
_extra: &Self::MemoryExtra,
216216
) -> InterpResult<'tcx, Pointer<Self::PointerTag>> {
217-
Err(InterpErrorInfo::from(InterpError::ReadBytesAsPointer))
217+
if int == 0 {
218+
Err(InterpErrorInfo::from(InterpError::InvalidNullPointerUsage))
219+
} else {
220+
Err(InterpErrorInfo::from(InterpError::ReadBytesAsPointer))
221+
}
218222
}
219223

220224
fn ptr_to_int(

0 commit comments

Comments
 (0)