diff --git a/src/lib.rs b/src/lib.rs index 3b6c477..3e3cb36 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,10 +9,22 @@ extern crate alloc; macro_rules! invalid_data_error { ($fmt:expr) => { - invalid_data_error!($fmt, "") + ::core2::io::Error::new(::core2::io::ErrorKind::InvalidData, $fmt) }; ($fmt:expr, $($arg:tt)*) => { - ::core2::io::Error::new(::core2::io::ErrorKind::InvalidData, $fmt) + { + #[cfg(feature = "std")] + { + ::core2::io::Error::new( + ::core2::io::ErrorKind::InvalidData, + ::alloc::format!($fmt, $($arg)*), + ) + } + #[cfg(not(feature = "std"))] + { + ::core2::io::Error::new(::core2::io::ErrorKind::InvalidData, $fmt) + } + } }; } diff --git a/src/zlib.rs b/src/zlib.rs index 914c78e..c45ae8e 100644 --- a/src/zlib.rs +++ b/src/zlib.rs @@ -932,4 +932,13 @@ mod tests { ]; assert_eq!(buf, decoded_data); } + + #[test] + #[cfg(feature = "std")] + fn issue_82() { + let encoded_data = [0x00, 0x00]; + let error = Header::read_from(&encoded_data[..]).unwrap_err(); + assert_eq!(error.kind(), io::ErrorKind::InvalidData); + assert!(error.to_string().contains("method=0")); + } }