Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions crates/oxc_parser/src/lexer/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,11 @@ impl<'a> Source<'a> {
/// Peek next two bytes of source without consuming them.
#[inline]
pub(super) fn peek_2_bytes(&self) -> Option<[u8; 2]> {
if (self.end as usize).saturating_sub(self.ptr as usize) >= 2 {
// `end` is always >= `ptr` so `end - ptr` cannot wrap around.
// No need to use checked/saturating subtraction here.
if (self.end as usize) - (self.ptr as usize) >= 2 {
// SAFETY: The check above ensures that there are at least 2 bytes to
// read from `self.ptr` without overflowing past `self.end`.
// read from `self.ptr` without reading past `self.end`
let bytes = unsafe { self.position().read2() };
Some(bytes)
} else {
Expand Down