diff options
| author | bors <bors@rust-lang.org> | 2016-11-06 23:05:58 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-11-06 23:05:58 -0800 |
| commit | 045a727b8362103052ae3c5f51ad24f069bbd43f (patch) | |
| tree | d35159895556b813f5f6b56db2240b8009f9de22 /src/liballoc | |
| parent | 09fc1af9d80ecb71c82367b6569461e645a3a946 (diff) | |
| parent | 99aaccd32fe7b63366fa13b48f485fd1cdcd8660 (diff) | |
| download | rust-045a727b8362103052ae3c5f51ad24f069bbd43f.tar.gz rust-045a727b8362103052ae3c5f51ad24f069bbd43f.zip | |
Auto merge of #37605 - dsprenkels:arc-max-refcount, r=alexcrichton
Fix Arc::clone()'s MAX_REFCOUNT check (off-by-one) Before, the strong count of an `Arc` could be set to `MAX_REFCOUNT + 1`, because when this happened, `old_size` would be exactly `MAX_REFCOUNT`. `Arc::clone()` would not abort. This commit changes the check in `Arc::clone()` to also abort if the old value is equal to `MAX_REFCOUNT`, because then the new value will be equal to `MAX_REFCOUNT + 1`. A test would require allocating memory for `isize::MAX` pointers. This would probably crash any machine, so no test is submitted with this commit.
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/arc.rs | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 7a07e007ce1..d6096d58947 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -36,6 +36,10 @@ use core::{isize, usize}; use core::convert::From; use heap::deallocate; +/// A soft limit on the amount of references that may be made to an `Arc`. +/// +/// Going above this limit will abort your program (although not +/// necessarily) at _exactly_ `MAX_REFCOUNT + 1` references. const MAX_REFCOUNT: usize = (isize::MAX) as usize; /// A thread-safe reference-counting pointer. |
