about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorAndrew Paseltiner <apaseltiner@gmail.com>2015-11-24 16:40:25 -0500
committerAndrew Paseltiner <apaseltiner@gmail.com>2015-11-24 16:40:25 -0500
commit0fc1f9a2edda6c08fb0857e780b49102420a4179 (patch)
treeeb5f9705e1f3de4d8ded6893bceea2e34f0d14d9 /src/liballoc
parentebb560a069c7edb9dc506fdc302dbf1c57576952 (diff)
downloadrust-0fc1f9a2edda6c08fb0857e780b49102420a4179.tar.gz
rust-0fc1f9a2edda6c08fb0857e780b49102420a4179.zip
Add overflow check to `arc::Weak::upgrade`
Closes #30031.
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/arc.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs
index dba9b71c61c..45a47ae075e 100644
--- a/src/liballoc/arc.rs
+++ b/src/liballoc/arc.rs
@@ -637,6 +637,11 @@ impl<T: ?Sized> Weak<T> {
                 return None
             }
 
+            // See comments in `Arc::clone` for why we do this (for `mem::forget`).
+            if n > MAX_REFCOUNT {
+                unsafe { abort(); }
+            }
+
             // Relaxed is valid for the same reason it is on Arc's Clone impl
             let old = inner.strong.compare_and_swap(n, n + 1, Relaxed);
             if old == n {