]> git.lizzy.rs Git - rust.git/commitdiff
std: Fix a bug where Local::take() didn't zero out
authorAlex Crichton <alex@alexcrichton.com>
Fri, 13 Dec 2013 02:05:37 +0000 (18:05 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 25 Dec 2013 03:59:52 +0000 (19:59 -0800)
In the compiled version of local_ptr (that with #[thread_local]), the take()
funciton didn't zero-out the previous pointer, allowing for multiple takes (with
fewer runtime assertions being tripped).

src/libstd/rt/local_ptr.rs

index 925aa802ad5c299626bb616a16e1644f8b0f3590..b75f2927003881a9b5e4354787b71b7908276a8b 100644 (file)
@@ -109,7 +109,9 @@ pub unsafe fn put<T>(sched: ~T) {
     /// Does not validate the pointer type.
     #[inline]
     pub unsafe fn take<T>() -> ~T {
-        let ptr: ~T = cast::transmute(RT_TLS_PTR);
+        let ptr = RT_TLS_PTR;
+        assert!(!ptr.is_null());
+        let ptr: ~T = cast::transmute(ptr);
         // can't use `as`, due to type not matching with `cfg(test)`
         RT_TLS_PTR = cast::transmute(0);
         ptr