Skip to content

Commit

Permalink
ravedude: Don't emit non-ascii bytes on Windows
Browse files Browse the repository at this point in the history
Windows console stdio does not support sending UTF-8 sequences which
means that we must ensure that any data received from the serial
connection is cleaned to ASCII only before forwarding it to the console.

To make sure that users notice the illegal data getting sent, print `?`
symbols instead.
  • Loading branch information
Rahix committed Mar 7, 2024
1 parent 0d12aef commit c01dbf2
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ravedude/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ pub fn open(port: &std::path::Path, baudrate: u32) -> anyhow::Result<()> {

match rx.read(&mut buf) {
Ok(count) => {
#[cfg(target_os = "windows")]
{
// On windows, we must ensure that we are not sending anything outside of the
// ASCII range.
for byte in &mut buf[..count] {
if *byte & 0x80 != 0 {
*byte = '?'.try_into().unwrap();
}
}
}
stdout.write(&buf[..count]).unwrap();
stdout.flush().unwrap();
}
Expand Down

0 comments on commit c01dbf2

Please sign in to comment.