Skip to content

Commit 0dc6c41

Browse files
committed
Check for null in return_to_mut. Fixes #4904.
1 parent 5f52669 commit 0dc6c41

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/libcore/unstable/lang.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,12 @@ pub unsafe fn borrow_as_imm(a: *u8) {
9999
#[lang="return_to_mut"]
100100
#[inline(always)]
101101
pub unsafe fn return_to_mut(a: *u8) {
102-
let a: *mut BoxRepr = transmute(a);
103-
(*a).header.ref_count &= !FROZEN_BIT;
102+
// Sometimes the box is null, if it is conditionally frozen.
103+
// See e.g. #4904.
104+
if !a.is_null() {
105+
let a: *mut BoxRepr = transmute(a);
106+
(*a).header.ref_count &= !FROZEN_BIT;
107+
}
104108
}
105109

106110
#[lang="check_not_borrowed"]

0 commit comments

Comments
 (0)