File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -647,15 +647,20 @@ pub const fn align_down(addr: u64, align: u64) -> u64 {
647
647
///
648
648
/// Returns the smallest `x` with alignment `align` so that `x >= addr`.
649
649
///
650
- /// Panics if the alignment is not a power of two.
650
+ /// Panics if the alignment is not a power of two or if an overflow occurs .
651
651
#[ inline]
652
652
pub const fn align_up ( addr : u64 , align : u64 ) -> u64 {
653
653
assert ! ( align. is_power_of_two( ) , "`align` must be a power of two" ) ;
654
654
let align_mask = align - 1 ;
655
655
if addr & align_mask == 0 {
656
656
addr // already aligned
657
657
} else {
658
- ( addr | align_mask) + 1
658
+ // FIXME: Replace with .expect, once `Option::expect` is const.
659
+ if let Some ( aligned) = ( addr | align_mask) . checked_add ( 1 ) {
660
+ aligned
661
+ } else {
662
+ panic ! ( "attempt to add with overflow" )
663
+ }
659
664
}
660
665
}
661
666
You can’t perform that action at this time.
0 commit comments