From 17744022b109c7cc6d22a0a339569391abdca7a4 Mon Sep 17 00:00:00 2001 From: Takeru Ohta Date: Sun, 15 Feb 2026 20:12:38 +0900 Subject: [PATCH 1/4] fix: improve invalid_data_error macro to support format arguments --- src/lib.rs | 4 ++-- src/zlib.rs | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3b6c477..857557b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,10 +9,10 @@ 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) + ::core2::io::Error::new(::core2::io::ErrorKind::InvalidData, format!($fmt, $($arg)*)) }; } diff --git a/src/zlib.rs b/src/zlib.rs index 914c78e..6f8d460 100644 --- a/src/zlib.rs +++ b/src/zlib.rs @@ -932,4 +932,12 @@ mod tests { ]; assert_eq!(buf, decoded_data); } + + #[test] + 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")); + } } From df5468f1c7a3d4ef3c9763e9f3cc91474aa378fd Mon Sep 17 00:00:00 2001 From: Takeru Ohta Date: Sun, 15 Feb 2026 20:14:57 +0900 Subject: [PATCH 2/4] fix: use alloc::format in invalid_data_error macro and improve formatting --- src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 857557b..4a34510 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,10 @@ macro_rules! invalid_data_error { ::core2::io::Error::new(::core2::io::ErrorKind::InvalidData, $fmt) }; ($fmt:expr, $($arg:tt)*) => { - ::core2::io::Error::new(::core2::io::ErrorKind::InvalidData, format!($fmt, $($arg)*)) + ::core2::io::Error::new( + ::core2::io::ErrorKind::InvalidData, + ::alloc::format!($fmt, $($arg)*), + ) }; } From f1c59c15d51c6637e7b407399aa7daf0f637adb5 Mon Sep 17 00:00:00 2001 From: Takeru Ohta Date: Sun, 15 Feb 2026 20:16:06 +0900 Subject: [PATCH 3/4] fix: add feature gate for format macro in invalid_data_error --- src/lib.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4a34510..3e3cb36 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,10 +12,19 @@ macro_rules! invalid_data_error { ::core2::io::Error::new(::core2::io::ErrorKind::InvalidData, $fmt) }; ($fmt:expr, $($arg:tt)*) => { - ::core2::io::Error::new( - ::core2::io::ErrorKind::InvalidData, - ::alloc::format!($fmt, $($arg)*), - ) + { + #[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) + } + } }; } From ddbcb3cfce18724720e21aaaea33c5436f9be495 Mon Sep 17 00:00:00 2001 From: Takeru Ohta Date: Sun, 15 Feb 2026 20:18:13 +0900 Subject: [PATCH 4/4] fix: add feature gate for issue_82 test --- src/zlib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/zlib.rs b/src/zlib.rs index 6f8d460..c45ae8e 100644 --- a/src/zlib.rs +++ b/src/zlib.rs @@ -934,6 +934,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn issue_82() { let encoded_data = [0x00, 0x00]; let error = Header::read_from(&encoded_data[..]).unwrap_err();