Repository navigation
Commit 98d49ed
zeroize: avoid double-zeroizing Vec's initialized elements (#1525)
Fixes #1524.
`Vec<Z>::zeroize()` previously:
1. Zeroizes the initialized elements via `iter_mut()`
2. Calls `clear()`, which resets `len` to 0
3. Zeroizes `spare_capacity_mut()`
Since `spare_capacity_mut()` covers everything beyond `len`, and `len`
is already 0 by step 3, it covers the *entire* allocation - re-zeroizing
the elements that were already zeroized in step 1.
This PR reorders the operations so the spare (truly uninitialized)
capacity is zeroed first, while `len` still reflects the real element
count. The two zeroing passes then cover disjoint ranges instead of
overlapping.
Behavior is unchanged - the full allocation is still zeroed - only the
redundant work is removed. Verified locally with `cargo test --features
alloc`: all existing tests pass, including
`zeroize_vec_entire_capacity`, which specifically checks that no
partially-zeroized or uninitialized data survives (this test's
ordering-sensitive assertions still hold under the new order - traced
through manually and confirmed via the test run).
---------
Co-authored-by: Tony Arcieri <bascule@gmail.com>1 parent 03a330e commit 98d49ed
1 file changed
Lines changed: 8 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
523 | 523 | | |
524 | 524 | | |
525 | 525 | | |
526 | | - | |
| 526 | + | |
527 | 527 | | |
528 | 528 | | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
529 | 535 | | |
530 | 536 | | |
531 | 537 | | |
532 | | - | |
| 538 | + | |
533 | 539 | | |
534 | | - | |
535 | | - | |
536 | | - | |
537 | 540 | | |
538 | 541 | | |
539 | 542 | | |
| |||
0 commit comments