Skip to content

Use unsafe slicing #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

zbraniecki
Copy link
Collaborator

Solves #82

@@ -148,7 +148,7 @@ impl<'p> ParserStream<'p> {
}

pub fn get_slice(&self, start: usize, end: usize) -> &'p str {
str::from_utf8(&self.source[start..end]).expect("Slicing the source failed")
unsafe { str::from_utf8_unchecked(&self.source[start..end]) }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should be unsafe. The start or end might not be at the start or end of a character, which makes the str invalid.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bjorn3 - please, comment in #82 where we're discussing it. In particular, I made a claim that the start and end must be at the start and end of a character due to how the parser works.

@zbraniecki zbraniecki closed this Sep 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants