From e0b0a9ed95993724494a7f6d9c737044638bf199 Mon Sep 17 00:00:00 2001 From: Dave McDaniel Date: Thu, 12 Sep 2024 13:11:32 -0400 Subject: [PATCH] address overflow on bitshift in backoff_time Fixes #29. --- src/lib.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 46e3ca1..f0b01a3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -490,9 +490,12 @@ impl BackgroundTask { }) } fn backoff_time(&self) -> (bool, Duration) { - let backoff_count: u64 = self.backoff_count.into(); - let backoff_time = if backoff_count >= 1 { - Duration::from_millis(500 * (1 << (backoff_count - 1))) + let backoff_time = if self.backoff_count >= 1 { + Duration::from_millis( + 500u64 + .checked_shl(self.backoff_count - 1) + .unwrap_or(u64::MAX), + ) } else { Duration::from_millis(0) };