diff options
author | Ben Bridle <bridle.benjamin@gmail.com> | 2024-08-10 14:34:00 +1200 |
---|---|---|
committer | Ben Bridle <bridle.benjamin@gmail.com> | 2024-08-10 14:37:02 +1200 |
commit | 59820850b2bd326a20306279bdcbe52982a74889 (patch) | |
tree | e1273725455707828bb64ce004099b556389bd1e | |
parent | 516f5cf5edfb7a2c4a4f3571aa6ce692a476d582 (diff) | |
download | bedrock-pc-59820850b2bd326a20306279bdcbe52982a74889.zip |
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.
-rw-r--r-- | src/devices/system/read_only_text_buffer.rs | 6 |
1 files changed, 3 insertions, 3 deletions
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) { |