Skip to content

Commit

Permalink
Prevent unintended truncation on numerical casts
Browse files Browse the repository at this point in the history
  • Loading branch information
uklotzde committed Feb 4, 2022
1 parent c0d4043 commit 1bbce58
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/codec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use bytes::{BufMut, Bytes, BytesMut};
use std::convert::TryFrom;
use std::io::{self, Cursor, Error, ErrorKind};

#[allow(clippy::cast_possible_truncation)]
fn u16_len(len: usize) -> u16 {
// This type conversion should always be safe, because either
// the caller is responsible to pass a valid usize or the
Expand All @@ -20,6 +21,7 @@ fn u16_len(len: usize) -> u16 {
len as u16
}

#[allow(clippy::cast_possible_truncation)]
fn u8_len(len: usize) -> u8 {
// This type conversion should always be safe, because either
// the caller is responsible to pass a valid usize or the
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
//#![deny(clippy::must_use_candidate)]
#![cfg_attr(not(test), warn(unsafe_code))]
#![cfg_attr(not(test), deny(clippy::panic_in_result_fn))]
#![cfg_attr(not(test), deny(clippy::cast_possible_truncation))]
#![cfg_attr(not(debug_assertions), deny(warnings))]
#![cfg_attr(not(debug_assertions), deny(clippy::used_underscore_binding))]

Expand Down

0 comments on commit 1bbce58

Please sign in to comment.