Repository navigation
Commit 71dd2f0
committed
zeroize: avoid double-zeroizing Vec's initialized elements
Vec<Z>::zeroize() zeroized the initialized elements via iter_mut(),
then called clear() (which resets len to 0), then zeroized
spare_capacity_mut(). Since spare_capacity_mut() covers everything
beyond len, and len was already 0 at that point, it covered the
entire allocation - re-zeroizing the elements that were already
zeroized in the first step.
Reorder so the spare (truly uninitialized) capacity is zeroed first,
while len still reflects the real element count, so the two zeroing
passes cover disjoint ranges. Behavior is unchanged (the full
allocation is still zeroed) other than removing the redundant work;
existing tests (including zeroize_vec_entire_capacity, which checks
no partially-zeroized or uninitialized data survives) still pass.
Fixes #15241 parent 03a330e commit 71dd2f0
1 file changed
Lines changed: 7 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
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