From 944365802f8ef53e37db38f15f2c2dc6b820d132 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Thu, 30 May 2024 11:49:35 -0500 Subject: [PATCH] nak: Only convert the written portion of the buffer in NirInstrPrinter Fixes: 02774be70887 ("nak/sm50: add a memstream abstraction") Part-of: --- src/nouveau/compiler/nak/nir_instr_printer.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/nouveau/compiler/nak/nir_instr_printer.rs b/src/nouveau/compiler/nak/nir_instr_printer.rs index bfd21e778d2..d46373c4932 100644 --- a/src/nouveau/compiler/nak/nir_instr_printer.rs +++ b/src/nouveau/compiler/nak/nir_instr_printer.rs @@ -32,8 +32,11 @@ impl NirInstrPrinter { unsafe { let stream = self.stream.as_mut().get_unchecked_mut(); nak_nir_asprint_instr(stream, instr); - let c_str = std::ffi::CStr::from_ptr(stream.buffer); - let string = c_str.to_string_lossy().into_owned(); + let bytes = std::slice::from_raw_parts( + stream.buffer as *const u8, + stream.written, + ); + let string = String::from_utf8_lossy(bytes).into_owned(); nak_clear_memstream(stream); string }