Skip to content

Commit df62919

Browse files
committed
lints: enable and address remaining trivial_numeric_casts
1 parent b18f7d6 commit df62919

3 files changed

Lines changed: 20 additions & 10 deletions

File tree

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ rustls = "0.23.27"
1818

1919
[dev-dependencies]
2020
pretty_assertions = "1"
21+
22+
[lints.rust]
23+
trivial_numeric_casts = "warn"

src/entry.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ entry! {
424424
protos_len: c_uint,
425425
) -> MysteriouslyOppositeReturnValue {
426426
let ctx = try_clone_arc!(ctx);
427-
let slice = try_slice!(protos, protos_len);
427+
let slice = try_slice!(protos, c_uint_into_usize(protos_len));
428428

429429
let alpn = match crate::parse_alpn(slice) {
430430
Some(alpn) => alpn,
@@ -689,7 +689,7 @@ entry! {
689689
sid_ctx: *const c_uchar,
690690
sid_ctx_len: c_uint,
691691
) -> c_int {
692-
let sid_ctx = try_slice!(sid_ctx, sid_ctx_len);
692+
let sid_ctx = try_slice!(sid_ctx, c_uint_into_usize(sid_ctx_len));
693693
if sid_ctx.len() > SSL_MAX_SID_CTX_LENGTH {
694694
return Error::not_supported("excess sid_ctx_len").raise().into();
695695
}
@@ -937,7 +937,7 @@ entry! {
937937
protos_len: c_uint,
938938
) -> MysteriouslyOppositeReturnValue {
939939
let ssl = try_clone_arc!(ssl);
940-
let slice = try_slice!(protos, protos_len);
940+
let slice = try_slice!(protos, c_uint_into_usize(protos_len));
941941

942942
let alpn = match crate::parse_alpn(slice) {
943943
Some(alpn) => alpn,
@@ -1131,8 +1131,8 @@ entry! {
11311131
ERROR
11321132
}
11331133
Ok(result) => match result {
1134-
ShutdownResult::Sent => 0 as c_int,
1135-
ShutdownResult::Received => 1 as c_int,
1134+
ShutdownResult::Sent => 0,
1135+
ShutdownResult::Received => 1,
11361136
},
11371137
}
11381138
}
@@ -1170,7 +1170,7 @@ entry! {
11701170

11711171
entry! {
11721172
pub fn _SSL_get_error(ssl: *const SSL, _ret_code: c_int) -> c_int {
1173-
try_clone_arc!(ssl).get_mut().get_error() as c_int
1173+
try_clone_arc!(ssl).get_mut().get_error()
11741174
}
11751175
}
11761176

@@ -1613,8 +1613,8 @@ entry! {
16131613
client: *const c_uchar,
16141614
client_len: c_uint,
16151615
) -> c_int {
1616-
let server = try_slice!(server, server_len);
1617-
let client = try_slice!(client, client_len);
1616+
let server = try_slice!(server, c_uint_into_usize(server_len));
1617+
let client = try_slice!(client, c_uint_into_usize(client_len));
16181618

16191619
if out.is_null() || out_len.is_null() {
16201620
return 0;
@@ -1732,7 +1732,7 @@ entry! {
17321732
sid_ctx: *const c_uchar,
17331733
sid_ctx_len: c_uint,
17341734
) -> c_int {
1735-
let slice = try_slice!(sid_ctx, sid_ctx_len);
1735+
let slice = try_slice!(sid_ctx, c_uint_into_usize(sid_ctx_len));
17361736
if slice.len() > SSL_MAX_SID_CTX_LENGTH {
17371737
return Error::not_supported("excess sid_ctx_len").raise().into();
17381738
}
@@ -2480,6 +2480,13 @@ entry_stub! {
24802480

24812481
// ---------------------
24822482

2483+
fn c_uint_into_usize(v: c_uint) -> usize {
2484+
const {
2485+
assert!(size_of::<c_uint>() <= size_of::<usize>());
2486+
}
2487+
v as usize
2488+
}
2489+
24832490
#[cfg(test)]
24842491
mod tests {
24852492
use super::*;

src/ffi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ macro_rules! try_slice {
418418
if $ptr.is_null() {
419419
return $crate::error::Error::null_pointer().raise().into();
420420
} else {
421-
unsafe { ::core::slice::from_raw_parts($ptr, $count as usize) }
421+
unsafe { ::core::slice::from_raw_parts($ptr, $count) }
422422
}
423423
};
424424
}

0 commit comments

Comments
 (0)