diff options
-rw-r--r-- | CHANGELOG | 4 | ||||
-rw-r--r-- | src/display/display_sink.rs | 4 | ||||
-rw-r--r-- | tests/display.rs | 29 |
3 files changed, 36 insertions, 1 deletions
@@ -13,6 +13,10 @@ TODO: impls of `fn one` and `fn zero` so downstream users don't have to import n TODO: 0.4.0 or later: * remove `mod colors`, crossterm dependency, related feature flags +## 0.3.1 + +fix InstructionTextSink::write_char to not panic in debug builds + ## 0.3.0 added a new crate feature flag, `alloc`. diff --git a/src/display/display_sink.rs b/src/display/display_sink.rs index f5ec026..e83f084 100644 --- a/src/display/display_sink.rs +++ b/src/display/display_sink.rs @@ -453,7 +453,9 @@ mod instruction_text_sink { // write single ASCII characters. this is wrong in the general case, but `write_char` // here is not going to be used in the general case. if cfg!(debug_assertions) { - panic!("InstructionTextSink::write_char would truncate output"); + if c > '\x7f' { + panic!("InstructionTextSink::write_char would truncate output"); + } } let to_push = c as u8; // `ptr::write` here because `underlying.add(underlying.len())` may not point to an diff --git a/tests/display.rs b/tests/display.rs index a6d6eb1..8826303 100644 --- a/tests/display.rs +++ b/tests/display.rs @@ -19,6 +19,35 @@ fn formatters_are_not_feature_gated() { #[cfg(feature="alloc")] #[test] +fn instruction_text_sink_write_char_requires_ascii() { + use core::fmt::Write; + + let mut text = String::with_capacity(512); + let mut sink = unsafe { + yaxpeax_arch::display::InstructionTextSink::new(&mut text) + }; + let expected = "`1234567890-=+_)(*&^%$#@!~\\][poiuytrewq |}{POIUYTREWQ';lkjhgfdsa\":LKJHGFDSA/.,mnbvcxz?><MNBVCXZ \r\n"; + for c in expected.as_bytes().iter() { + sink.write_char(*c as char).expect("write works"); + } + assert_eq!(text, expected); +} + +#[cfg(feature="alloc")] +#[test] +#[should_panic] +fn instruction_text_sink_write_char_rejects_not_ascii() { + use core::fmt::Write; + + let mut text = String::with_capacity(512); + let mut sink = unsafe { + yaxpeax_arch::display::InstructionTextSink::new(&mut text) + }; + sink.write_char('\u{80}').expect("write works"); +} + +#[cfg(feature="alloc")] +#[test] fn display_sink_write_hex_helpers() { use yaxpeax_arch::display::{DisplaySink}; |