summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2026-02-27 11:40:53 +0100
committerThomas Voss <mail@thomasvoss.com> 2026-02-27 11:40:53 +0100
commite5d3c3f3d0dfcc399ef1f7623ddeab619db4b4ea (patch)
treec18eed140b27ce3cd61c0f5ef99e126c69031298
parentdf512a08f3c14f8496b53dd15f30f772df208202 (diff)
Bad the input buffer with nul bytes
-rw-r--r--oryxc/src/compiler.rs8
-rw-r--r--oryxc/src/lexer.rs2
2 files changed, 8 insertions, 2 deletions
diff --git a/oryxc/src/compiler.rs b/oryxc/src/compiler.rs
index 14919ba..bdb4475 100644
--- a/oryxc/src/compiler.rs
+++ b/oryxc/src/compiler.rs
@@ -44,7 +44,13 @@ pub struct FileData {
impl FileData {
fn new(name: OsString) -> Result<Self, io::Error> {
- let buffer = fs::read_to_string(&name)?;
+ const PAD: [u8; 64] = [0; 64]; /* 512 bits */
+
+ // Append extra data to the end so that we can safely read past
+ // instead of branching on length
+ let mut buffer = fs::read_to_string(&name)?;
+ buffer.push_str(unsafe { str::from_utf8_unchecked(&PAD) });
+
return Ok(Self {
name: name.into(),
buffer: buffer.into(),
diff --git a/oryxc/src/lexer.rs b/oryxc/src/lexer.rs
index 6457cfd..f5f4c85 100644
--- a/oryxc/src/lexer.rs
+++ b/oryxc/src/lexer.rs
@@ -142,7 +142,7 @@ impl<'a> LexerContext<'a> {
let c = self.chars.next()?;
self.pos_b = self.pos_a;
self.pos_a += c.len_utf8();
- return Some(c);
+ return if c == '\0' { None } else { Some(c) };
}
#[inline(always)]