rust/library/alloc
Matthias Krüger 7fb81229d3
Rollup merge of #123803 - Sp00ph:shrink_to_fix, r=Mark-Simulacrum
Fix `VecDeque::shrink_to` UB when `handle_alloc_error` unwinds.

Fixes #123369

For `VecDeque` it's relatively simple to restore the buffer into a consistent state so this PR does just that.

Note that with its current implementation, `shrink_to` may change the internal arrangement of elements in the buffer, so e.g. `[D, <uninit>, A, B, C]` will become `[<uninit>, A, B, C, D]` and `[<uninit>, <uninit>, A, B, C]` may become `[B, C, <uninit>, <uninit>, A]` if `shrink_to` unwinds. This shouldn't be an issue though as we don't make any guarantees about the stability of the internal buffer arrangement (and this case is impossible to hit on stable anyways).

This PR also includes a test with code adapted from #123369 which fails without the new `shrink_to` code. Does this suffice or do we maybe need more exhaustive tests like in #108475?

cc `@Amanieu`

`@rustbot` label +T-libs
2024-05-25 22:15:17 +02:00
..
benches disable benches in Miri 2024-04-07 09:58:10 +02:00
src Rollup merge of #123803 - Sp00ph:shrink_to_fix, r=Mark-Simulacrum 2024-05-25 22:15:17 +02:00
tests Rollup merge of #123803 - Sp00ph:shrink_to_fix, r=Mark-Simulacrum 2024-05-25 22:15:17 +02:00
Cargo.toml Rollup merge of #123803 - Sp00ph:shrink_to_fix, r=Mark-Simulacrum 2024-05-25 22:15:17 +02:00