Skip to content

Commit 302a325

Browse files
committed
Bail-out early if reinterpreted pointer is null
1 parent 7e10a1d commit 302a325

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

libcc2rs/src/rc.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,13 +402,17 @@ impl<T> Ptr<T> {
402402
return self_any.downcast_ref::<Ptr<U>>().unwrap().clone();
403403
}
404404

405+
if self.is_null() {
406+
return Ptr::null();
407+
}
408+
405409
if U::byte_size() == 0 {
406410
panic!("cannot reinterpret_cast to zero-sized type");
407411
}
408412

409413
let src_byte_off = self.offset.wrapping_mul(T::byte_size());
410414
let (alloc, abs_byte_off): (Rc<dyn OriginalAlloc>, usize) = match &self.kind {
411-
PtrKind::Null => return Ptr::null(),
415+
PtrKind::Null => unreachable!(),
412416
PtrKind::StackSingle(weak) | PtrKind::HeapSingle(weak) => (
413417
Rc::new(SingleOriginalAlloc { weak: weak.clone() }),
414418
src_byte_off,

0 commit comments

Comments
 (0)