From 1ea2f68e6a9af135e6cb3274fdf28d4ddc5812d5 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sat, 1 Aug 2026 18:25:55 +0200 Subject: fix pi-lens warnings: unwraps, shell SC2046, dup code (fmtbuf/scripts/hexdump/cat/ahci/pci) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - memory.rs: self-test Layout::from_size_align no longer panics — the test fails cleanly on an invalid layout - fat.rs: v() no longer unwraps the active-volume slot — invariant violation logs + halts instead of panicking mid-disk-io - strbuf: shared FmtBuf replaces the duplicated PanicBuf/FmtBuf (main.rs + sched.rs) - test-disk.sh: SC2046 — conditional --fresh arg no longer relies on word splitting - scripts: boot.sh/boot-image.sh share lib-boot-args.sh (dup args loop) - shell: cat/hexdump stdin pairs unified with Option<&str> marker; hexdump format_row folded into format_partial - ahci: read/write_sectors unified behind dma_sectors - pci: config_read/write share config_addr --- rsnix/src/strbuf.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'rsnix/src/strbuf.rs') diff --git a/rsnix/src/strbuf.rs b/rsnix/src/strbuf.rs index 262720d..0e3ea56 100644 --- a/rsnix/src/strbuf.rs +++ b/rsnix/src/strbuf.rs @@ -69,3 +69,31 @@ impl fmt::Debug for String { write!(f, "{:?}", self.as_str()) } } + +/// Small `fmt::Write` over a byte slice — no allocation, bounded. +/// Shared by the panic handler (task-panic message) and the scheduler +/// (page-fault abort message) so they don't each reinvent it. +pub struct FmtBuf<'a> { + b: &'a mut [u8], + n: usize, +} + +impl<'a> FmtBuf<'a> { + pub fn new(b: &'a mut [u8]) -> Self { + FmtBuf { b, n: 0 } + } + + /// Bytes written so far (clamped at the buffer length). + pub fn len(&self) -> usize { + self.n + } +} + +impl fmt::Write for FmtBuf<'_> { + fn write_str(&mut self, s: &str) -> fmt::Result { + let m = s.len().min(self.b.len() - self.n); + self.b[self.n..self.n + m].copy_from_slice(&s.as_bytes()[..m]); + self.n += m; + Ok(()) + } +} -- cgit v1.2.3