From 0fc1f9a2edda6c08fb0857e780b49102420a4179 Mon Sep 17 00:00:00 2001 From: Andrew Paseltiner Date: Tue, 24 Nov 2015 16:40:25 -0500 Subject: [PATCH] Add overflow check to `arc::Weak::upgrade` Closes #30031. --- src/liballoc/arc.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index dba9b71c61cd4..45a47ae075e72 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -637,6 +637,11 @@ impl Weak { 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 {