Skip to content

Commit 289f189

Browse files
committed
Cast libc::spwd long int fields to i64
1 parent ca544ae commit 289f189

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/shadow.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,22 @@ pub struct Shadow {
8383

8484
impl From<&libc::spwd> for Shadow {
8585
fn from(spwd: &libc::spwd) -> Shadow {
86-
unsafe {
87-
Shadow {
88-
name: CStr::from_ptr((*spwd).sp_namp)
86+
Shadow {
87+
name: unsafe {
88+
CStr::from_ptr(spwd.sp_namp)
8989
.to_string_lossy()
90-
.into_owned(),
91-
password: CString::new(CStr::from_ptr((*spwd).sp_pwdp).to_bytes()).unwrap(),
92-
last_change: (*spwd).sp_lstchg,
93-
min: (*spwd).sp_min,
94-
max: (*spwd).sp_max,
95-
warn: (*spwd).sp_warn,
96-
inactive: (*spwd).sp_inact,
97-
expire: (*spwd).sp_expire,
98-
}
90+
.into_owned()
91+
},
92+
password: unsafe { CString::new(CStr::from_ptr(spwd.sp_pwdp).to_bytes()).unwrap() },
93+
// These casts are necessary to convert the C `long int`
94+
// integers (which can be either 32 or 64 bits, depending on
95+
// the CPU architecture) into 64 bit integers.
96+
last_change: spwd.sp_lstchg as i64,
97+
min: spwd.sp_min as i64,
98+
max: spwd.sp_max as i64,
99+
warn: spwd.sp_warn as i64,
100+
inactive: spwd.sp_inact as i64,
101+
expire: spwd.sp_expire as i64,
99102
}
100103
}
101104
}

0 commit comments

Comments
 (0)