about summary refs log tree commit diff
path: root/src/libstd/sys/unix/args.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-04-19 17:12:17 +0000
committerbors <bors@rust-lang.org>2019-04-19 17:12:17 +0000
commit130dc3e7dac132cf30272ccf4541b512828e2108 (patch)
tree7dbba29cf92a6a02a0d2a20939fee701cb44d6fc /src/libstd/sys/unix/args.rs
parenta2bbf7debaab60be33bd8008a71bca69576945a0 (diff)
parent8b09d046fedf84ed869204bbe0779a0439bbf9eb (diff)
downloadrust-130dc3e7dac132cf30272ccf4541b512828e2108.tar.gz
rust-130dc3e7dac132cf30272ccf4541b512828e2108.zip
Auto merge of #60072 - RalfJung:linked-list, r=shepmaster
fix LinkedList invalidating mutable references

The test `test_insert_prev` failed in Miri due to what I consider a bug in `LinkedList`: in various places, `NonNull::as_mut` got called to modify the `prev`/`next` pointers of existing nodes. In particular, the unstable `insert_next` has to modify the `next` pointer of the node that was last handed out by the iterator; to this end it creates a mutable reference to the *entire node* that overlaps with the mutable reference to the node's content that was handed out by the iterator! Thus, the next use if said mutable reference is UB.

In code:
```rust
            loop {
                match it.next() { // mutable reference handed to us
                    None => break,
                    Some(elt) => {
                        it.insert_next(*elt + 1); // this invalidates `elt` because it creates an overlapping mutable reference
                        match it.peek_next() {
                            Some(x) => assert_eq!(*x, *elt + 2), // this use of `elt` now is a use of an invalid pointer
                            None => assert_eq!(8, *elt),
                        }
                    }
                }
            }
```

This PR fixes that by using `as_ptr` instead of `as_mut`. This avoids invalidating the mutable reference that was handed to the user.  I did this in all methods called by iterators, just to be sure.

Cc @Gankro
Diffstat (limited to 'src/libstd/sys/unix/args.rs')
0 files changed, 0 insertions, 0 deletions