kms: protect against potential overflow of Duration when calculating avg frametime

Also see: https://github.com/Smithay/smithay/pull/1685

Fixes #1062

Co-authored-by: Victoria Brekenfeld <victoria@system76.com>
This commit is contained in:
Clayton Craft 2025-03-19 09:11:30 -07:00 committed by Victoria Brekenfeld
parent dbd43d7582
commit 8f40fc7a1b

View file

@ -213,7 +213,7 @@ impl Timings {
.rev()
.take(window)
.map(|f| f.frame_time())
.sum::<Duration>()
.try_fold(Duration::ZERO, |acc, x| acc.checked_add(x))?
/ (window.min(self.previous_frames.len()) as u32),
)
}