Skip to content

Commit 045a727

Browse files
authored
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.
2 parents 09fc1af + 99aaccd commit 045a727

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/liballoc/arc.rs

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ use core::{isize, usize};
3636
use core::convert::From;
3737
use heap::deallocate;
3838

39+
/// A soft limit on the amount of references that may be made to an `Arc`.
40+
///
41+
/// Going above this limit will abort your program (although not
42+
/// necessarily) at _exactly_ `MAX_REFCOUNT + 1` references.
3943
const MAX_REFCOUNT: usize = (isize::MAX) as usize;
4044

4145
/// A thread-safe reference-counting pointer.

0 commit comments

Comments
 (0)