Skip to content

Commit

Permalink
chore: Add a feature gate to allow user disabling the NaN check
Browse files Browse the repository at this point in the history
  • Loading branch information
dqhl76 committed Sep 3, 2024
1 parent f16cd07 commit fd4e597
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions borsh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ std = []
# Be sure that this is what you want before enabling this feature.
rc = []
de_strict_order = []
allow_nan = []
1 change: 1 addition & 0 deletions borsh/src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ macro_rules! impl_for_float {
.read_exact(&mut buf)
.map_err(unexpected_eof_to_unexpected_length_of_input)?;
let res = $type::from_bits($int_type::from_le_bytes(buf.try_into().unwrap()));
#[cfg(not(feature = "allow_nan"))]
if res.is_nan() {
return Err(Error::new(
ErrorKind::InvalidData,
Expand Down
1 change: 1 addition & 0 deletions borsh/src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ macro_rules! impl_for_float {
impl BorshSerialize for $type {
#[inline]
fn serialize<W: Write>(&self, writer: &mut W) -> Result<()> {
#[cfg(not(feature = "allow_nan"))]
if self.is_nan() {
return Err(Error::new(ErrorKind::InvalidData, FLOAT_NAN_ERR));
}
Expand Down

0 comments on commit fd4e597

Please sign in to comment.