Skip to content

Commit 72ed1f1

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

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/shadow.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,18 @@ 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)
89-
.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-
}
86+
Shadow {
87+
name: unsafe { CStr::from_ptr(spwd.sp_namp).to_string_lossy().into_owned() },
88+
password: unsafe { CString::new(CStr::from_ptr(spwd.sp_pwdp).to_bytes()).unwrap() },
89+
// These casts are necessary to convert the C `long int`
90+
// integers (which can be either 32 or 64 bits, depending on
91+
// the CPU architecture) into 64 bit integers.
92+
last_change: spwd.sp_lstchg as i64,
93+
min: spwd.sp_min as i64,
94+
max: spwd.sp_max as i64,
95+
warn: spwd.sp_warn as i64,
96+
inactive: spwd.sp_inact as i64,
97+
expire: spwd.sp_expire as i64,
9998
}
10099
}
101100
}

0 commit comments

Comments
 (0)