From cae86b2bfe8bd5bfe2e4fe9da4dba7317e8d3c8f Mon Sep 17 00:00:00 2001 From: arthurprs Date: Sat, 28 Dec 2019 20:18:10 +0100 Subject: [PATCH] Fix i32 overflow in Connection::busy_timeout --- src/busy.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/busy.rs b/src/busy.rs index fd0f949..76f6abe 100644 --- a/src/busy.rs +++ b/src/busy.rs @@ -1,4 +1,5 @@ ///! Busy handler (when the database is locked) +use std::convert::TryInto; use std::mem; use std::os::raw::{c_int, c_void}; use std::panic::catch_unwind; @@ -21,12 +22,13 @@ impl Connection { /// (using `busy_handler`) prior to calling this routine, that other /// busy handler is cleared. pub fn busy_timeout(&self, timeout: Duration) -> Result<()> { - let ms = timeout + let ms: i32 = timeout .as_secs() .checked_mul(1000) .and_then(|t| t.checked_add(timeout.subsec_millis().into())) + .and_then(|t| t.try_into().ok()) .expect("too big"); - self.db.borrow_mut().busy_timeout(ms as i32) + self.db.borrow_mut().busy_timeout(ms) } /// Register a callback to handle `SQLITE_BUSY` errors.