From 6a301381c8e34e24d2d3e59c44815ac4cf61d2f9 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Fri, 5 May 2023 19:03:29 -0500 Subject: [PATCH] Fix compilation on 32-bit non-Linux platforms The `u64::from(buf.f_flag)` was needed in two places. The existing handled macOS which always has a 32-bit statfs::f_flag, but statvfs::f_flag is an `unsigned long` which means it needs to be coerced to 64-bits on 32-bit targets. --- fish-rust/src/path.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fish-rust/src/path.rs b/fish-rust/src/path.rs index 96c64ad78..b7e3c541d 100644 --- a/fish-rust/src/path.rs +++ b/fish-rust/src/path.rs @@ -686,7 +686,9 @@ fn path_remoteness(path: &wstr) -> DirRemoteness { if unsafe { libc::statvfs(narrow.as_ptr(), &mut buf) } < 0 { return DirRemoteness::unknown; } - return if buf.f_flag & st_local != 0 { + // statvfs::f_flag is `unsigned long`, which is 4-bytes on most 32-bit targets. + #[cfg_attr(target_pointer_width = "64", allow(clippy::useless_conversion))] + return if u64::from(buf.f_flag) & st_local != 0 { DirRemoteness::local } else { DirRemoteness::remote @@ -698,6 +700,9 @@ fn path_remoteness(path: &wstr) -> DirRemoteness { if unsafe { libc::statfs(narrow.as_ptr(), &mut buf) } < 0 { return DirRemoteness::unknown; } + // statfs::f_flag is hard-coded as 64-bits on 32/64-bit FreeBSD but it's a (4-byte) + // long on 32-bit NetBSD.. and always 4-bytes on macOS (even on 64-bit builds). + #[allow(clippy::useless_conversion)] return if u64::from(buf.f_flags) & mnt_local != 0 { DirRemoteness::local } else {