Skip to content

Commit

Permalink
Rollup merge of rust-lang#56648 - RalfJung:btree, r=sfackler
Browse files Browse the repository at this point in the history
Fix BTreeMap UB

BTreeMap currently causes UB by created a shared reference to a too-small allocation.  This PR fixes that by introducing a `NodeHeader` type and using that until we really need access to the key/value arrays.  Avoiding run-time checks in `into_key_slice` was somewhat tricky, see the comments embedded in the code.

I also adjusted `as_leaf_mut` to return a raw pointer, because creating a mutable reference asserts that there are no aliases to the pointee, but that's not always correct: We use `as_leaf_mut` twice to create two mutable slices for keys and values; the second call overlaps with the first slice and hence is not a unique pointer.

Fixes rust-lang#54957

Cc @nikomatsakis @gankro
  • Loading branch information
Centril authored Dec 16, 2018
2 parents 32f922e + d9c64e5 commit 9133798
Showing 1 changed file with 117 additions and 57 deletions.
Loading

0 comments on commit 9133798

Please sign in to comment.