From f8f10530f16c169f2ea1667766221352c71514d8 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Mon, 29 Jan 2024 14:33:15 +0100 Subject: [PATCH] printbuf_to_formatter: Lossy display of non-UTF-8 printbufs 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bch_bindgen/src/lib.rs b/bch_bindgen/src/lib.rs index deb69a51..ea49e60b 100644 --- a/bch_bindgen/src/lib.rs +++ b/bch_bindgen/src/lib.rs @@ -164,5 +164,5 @@ pub fn printbuf_to_formatter(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()) }