]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
printbuf_to_formatter: Lossy display of non-UTF-8 printbufs
authorGabriel <g2p.code@gmail.com>
Mon, 29 Jan 2024 13:33:15 +0000 (14:33 +0100)
committerGabriel <g2p.code@gmail.com>
Mon, 29 Jan 2024 13:34:24 +0000 (14:34 +0100)
Use to_string_lossy in printbuf_to_formatter, which tolerates
non-UTF-8 strings (by using replacement characters).

This is used in various Display impls, and allows something like:
bcachefs list --btree dirents
with non-UTF-8 paths.

bch_bindgen/src/lib.rs

index deb69a5169907124e6f19e9d5baa9e2c1b995cf2..ea49e60beed35b548d3d7c50b4a3fd4eaf2c0ebf 100644 (file)
@@ -164,5 +164,5 @@ pub fn printbuf_to_formatter<F>(f: &mut fmt::Formatter<'_>, func: F) -> fmt::Res
     func(&mut buf);
 
     let s = unsafe { CStr::from_ptr(buf.buf) };
-    f.write_str(s.to_str().unwrap())
+    f.write_str(&s.to_string_lossy())
 }