Commit de7bb5b
committed
RawVecInner: add missing
- RawVecInner::grow_exact causes UB if called with len and additional
arguments such that len + additional is less than the current
capacity. Indeed, in that case it calls Allocator::grow with a
new_layout that is smaller than old_layout, which violates a safety
precondition.
- RawVecInner::grow_exact and RawVecInner::grow_amortized both cause UB
if called with an elem_layout different from the one used to initially
allocate the buffer, because in that case Allocator::grow is called with
an old_layout that does not fit the allocated block, which violates a
safety precondition.
- Since RawVecInner::try_reserve and RawVecInner::try_reserve_exact call
RawVecInner::grow_amortized and RawVecInner::grow_exact, they also cause
UB if called with an elem_layout different from the one used to
initially allocate the buffer.
- Furthermore, these methods cause UB if called with an elem_layout
where the size is not a multiple of the alignment. This is because
Layout::repeat is used (in layout_array) to compute the allocation's
layout when allocating, which includes padding to ensure alignment of
array elements, but simple multiplication is used (in current_memory) to
compute the old allocation's layout when resizing or deallocating, which
would cause the layout used to resize or deallocate to not fit the
allocated block, which violates a safety precondition.unsafe to unsafe fns1 parent 321a89b commit de7bb5b
1 file changed
+28
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
340 | | - | |
| 340 | + | |
| 341 | + | |
341 | 342 | | |
342 | 343 | | |
343 | 344 | | |
| |||
346 | 347 | | |
347 | 348 | | |
348 | 349 | | |
349 | | - | |
| 350 | + | |
| 351 | + | |
350 | 352 | | |
351 | 353 | | |
352 | 354 | | |
| |||
369 | 371 | | |
370 | 372 | | |
371 | 373 | | |
372 | | - | |
| 374 | + | |
| 375 | + | |
373 | 376 | | |
374 | 377 | | |
375 | 378 | | |
| |||
378 | 381 | | |
379 | 382 | | |
380 | 383 | | |
381 | | - | |
| 384 | + | |
| 385 | + | |
382 | 386 | | |
383 | 387 | | |
384 | 388 | | |
| |||
554 | 558 | | |
555 | 559 | | |
556 | 560 | | |
557 | | - | |
| 561 | + | |
| 562 | + | |
558 | 563 | | |
559 | 564 | | |
560 | 565 | | |
| |||
567 | 572 | | |
568 | 573 | | |
569 | 574 | | |
570 | | - | |
571 | | - | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
572 | 578 | | |
573 | 579 | | |
574 | 580 | | |
575 | 581 | | |
576 | | - | |
| 582 | + | |
577 | 583 | | |
578 | 584 | | |
579 | 585 | | |
580 | 586 | | |
581 | 587 | | |
582 | 588 | | |
583 | | - | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
584 | 593 | | |
585 | 594 | | |
586 | 595 | | |
| |||
591 | 600 | | |
592 | 601 | | |
593 | 602 | | |
594 | | - | |
595 | | - | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
596 | 606 | | |
597 | 607 | | |
598 | 608 | | |
599 | 609 | | |
600 | | - | |
| 610 | + | |
601 | 611 | | |
602 | 612 | | |
603 | 613 | | |
604 | 614 | | |
605 | 615 | | |
606 | 616 | | |
607 | | - | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
608 | 621 | | |
609 | 622 | | |
610 | 623 | | |
| |||
636 | 649 | | |
637 | 650 | | |
638 | 651 | | |
639 | | - | |
| 652 | + | |
640 | 653 | | |
641 | 654 | | |
642 | 655 | | |
| |||
668 | 681 | | |
669 | 682 | | |
670 | 683 | | |
671 | | - | |
| 684 | + | |
672 | 685 | | |
673 | 686 | | |
674 | 687 | | |
| |||
0 commit comments