From e0cfe8e4d79a5a77e2f21811602f9c2ebe19359f Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sat, 21 Sep 2024 13:04:44 +0300 Subject: [PATCH] Fix compilation for 32-bit architectures Signed-off-by: Manos Pitsidianakis --- melib/src/gpgme/io.rs | 17 ++++++++++++++--- melib/src/notmuch/mod.rs | 6 ++++-- melib/src/utils/datetime.rs | 2 +- melib/src/utils/shellexpand.rs | 2 +- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/melib/src/gpgme/io.rs b/melib/src/gpgme/io.rs index a91371cf..a1c10fa9 100644 --- a/melib/src/gpgme/io.rs +++ b/melib/src/gpgme/io.rs @@ -224,13 +224,24 @@ impl Seek for Data { #[inline] fn seek(&mut self, pos: io::SeekFrom) -> io::Result { let (off, whence) = match pos { - io::SeekFrom::Start(off) => (off.try_into().unwrap_or(i64::MAX), libc::SEEK_SET), + io::SeekFrom::Start(off) => ( + off.try_into() + .map_err(|_| io::Error::from_raw_os_error(libc::EOVERFLOW))?, + libc::SEEK_SET, + ), io::SeekFrom::End(off) => (off.saturating_abs(), libc::SEEK_END), io::SeekFrom::Current(off) => (off, libc::SEEK_CUR), }; - let result = unsafe { call!(self.lib, gpgme_data_seek)(self.inner.as_ptr(), off, whence) }; + let result = unsafe { + call!(self.lib, gpgme_data_seek)( + self.inner.as_ptr(), + libc::off_t::try_from(off) + .map_err(|_| io::Error::from_raw_os_error(libc::EOVERFLOW))?, + whence, + ) + }; if result >= 0 { - Ok(result as u64) + Ok(u64::try_from(result).map_err(|_| io::Error::from_raw_os_error(libc::EOVERFLOW))?) } else { Err(io::Error::last_os_error()) } diff --git a/melib/src/notmuch/mod.rs b/melib/src/notmuch/mod.rs index 6553b555..b0518fba 100644 --- a/melib/src/notmuch/mod.rs +++ b/melib/src/notmuch/mod.rs @@ -111,12 +111,14 @@ pub struct DbConnection { impl DbConnection { pub fn get_revision_uuid(&self) -> u64 { - unsafe { + let ret: ::std::os::raw::c_ulong = unsafe { call!(self.lib, notmuch_database_get_revision)( self.inner.lock().unwrap().as_mut(), std::ptr::null_mut(), ) - } + }; + #[allow(clippy::useless_conversion)] + u64::from(ret) } #[allow(clippy::too_many_arguments)] // Don't judge me clippy. diff --git a/melib/src/utils/datetime.rs b/melib/src/utils/datetime.rs index 4c921530..36b46ac9 100644 --- a/melib/src/utils/datetime.rs +++ b/melib/src/utils/datetime.rs @@ -207,7 +207,7 @@ fn timestamp_to_string_inner( ) -> String { let mut new_tm: libc::tm = unsafe { std::mem::zeroed() }; unsafe { - let i: i64 = timestamp.try_into().unwrap_or(0); + let i = timestamp.try_into().unwrap_or(0); if local { localtime_r(std::ptr::addr_of!(i), std::ptr::addr_of_mut!(new_tm)); } else { diff --git a/melib/src/utils/shellexpand.rs b/melib/src/utils/shellexpand.rs index 230b365c..c526162f 100644 --- a/melib/src/utils/shellexpand.rs +++ b/melib/src/utils/shellexpand.rs @@ -261,7 +261,7 @@ pub mod impls { let mut buf: Vec = vec![0; BUF_SIZE * std::mem::size_of::<::libc::dirent64>()]; let mut entries = Vec::new(); loop { - let n: i64 = unsafe { + let n = unsafe { ::libc::syscall( ::libc::SYS_getdents64, dir.as_raw_fd(),