File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -328,12 +328,15 @@ impl Duration {
328328 #[ inline]
329329 pub const fn from_nanos_u128 ( nanos : u128 ) -> Duration {
330330 const NANOS_PER_SEC : u128 = self :: NANOS_PER_SEC as u128 ;
331- let secs: u64 = ( nanos / NANOS_PER_SEC ) as u64 ;
331+ let secs: u128 = ( nanos / NANOS_PER_SEC ) ;
332+ if ( secs > u64:: MAX . into ( ) ) {
333+ panic ! ( "overflow in duration in Duration::from_nanos_u128" ) ;
334+ }
332335 let subsec_nanos = ( nanos % NANOS_PER_SEC ) as u32 ;
333336 // SAFETY: x % 1_000_000_000 < 1_000_000_000
334337 let subsec_nanos = unsafe { Nanoseconds :: new_unchecked ( subsec_nanos) } ;
335338
336- Duration { secs, nanos : subsec_nanos }
339+ Duration { secs : secs as u64 , nanos : subsec_nanos }
337340 }
338341
339342 /// Creates a new `Duration` from the specified number of weeks.
You can’t perform that action at this time.
0 commit comments