File tree 1 file changed +5
-1
lines changed
1 file changed +5
-1
lines changed Original file line number Diff line number Diff line change @@ -636,6 +636,9 @@ impl<'a> Arguments<'a> {
636
636
/// when using `format!`. Note: this is neither the lower nor upper bound.
637
637
#[ inline]
638
638
pub fn estimated_capacity ( & self ) -> usize {
639
+ // Since the format args are constructed from a single string literal in
640
+ // `format_args!`, the total length of the pieces is under `isize::MAX`
641
+ // and this sum cannot overflow.
639
642
let pieces_length: usize = self . pieces . iter ( ) . map ( |x| x. len ( ) ) . sum ( ) ;
640
643
641
644
if self . args . is_empty ( ) {
@@ -649,7 +652,8 @@ impl<'a> Arguments<'a> {
649
652
// There are some arguments, so any additional push
650
653
// will reallocate the string. To avoid that,
651
654
// we're "pre-doubling" the capacity here.
652
- pieces_length. checked_mul ( 2 ) . unwrap_or ( 0 )
655
+ // It cannot overflow, because the maximum length is `isize::MAX`.
656
+ pieces_length * 2
653
657
}
654
658
}
655
659
}
You can’t perform that action at this time.
0 commit comments