From 59820850b2bd326a20306279bdcbe52982a74889 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Sat, 10 Aug 2024 14:34:00 +1200 Subject: Fix panic in ReadOnlyTextBuffer Previously when reading from a ReadOnlyTextBuffer the pointer would fall off the end and crash the emulator. This commit also makes the ReadOnlyTextBuffer Unicode-compatible, rather than the previous behaviour of clamping every character into the ASCII range. --- src/devices/system/read_only_text_buffer.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/devices/system') diff --git a/src/devices/system/read_only_text_buffer.rs b/src/devices/system/read_only_text_buffer.rs index 7c59025..dae1024 100644 --- a/src/devices/system/read_only_text_buffer.rs +++ b/src/devices/system/read_only_text_buffer.rs @@ -6,15 +6,15 @@ pub struct ReadOnlyTextBuffer { impl ReadOnlyTextBuffer { pub fn from_text(text: &str) -> Self { Self { - chars: text.chars().map(|c| c as u32 as u8).collect(), + chars: text.bytes().collect(), pointer: 0, } } pub fn read_byte(&mut self) -> u8 { - let byte = self.chars[self.pointer]; + let option = self.chars.get(self.pointer); self.pointer += 1; - return byte; + *option.unwrap_or(&0) } pub fn reset_pointer(&mut self) { -- cgit v1.2.3-70-g09d2