]> git.lizzy.rs Git - rust.git/commitdiff
Prevent the borrow counter from overflowing in `Ref::clone`
authorTobias Bucher <tobiasbucher5991@gmail.com>
Mon, 30 May 2016 07:53:09 +0000 (09:53 +0200)
committerTobias Bucher <tobiasbucher5991@gmail.com>
Mon, 30 May 2016 07:53:09 +0000 (09:53 +0200)
Fixes #33880.

src/libcore/cell.rs

index 4929088201deaa8f7400f634e4243b629d67733f..97a85f6aa43d006cf77930df3169168e95b53bfa 100644 (file)
@@ -618,7 +618,9 @@ fn clone(&self) -> BorrowRef<'b> {
         // Since this Ref exists, we know the borrow flag
         // is not set to WRITING.
         let borrow = self.borrow.get();
-        debug_assert!(borrow != WRITING && borrow != UNUSED);
+        debug_assert!(borrow != UNUSED);
+        // Prevent the borrow counter from overflowing.
+        assert!(borrow != WRITING);
         self.borrow.set(borrow + 1);
         BorrowRef { borrow: self.borrow }
     }