Skip to content
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

Panic in parse_text_lossy #141

Open
moulins opened this issue Mar 24, 2022 · 0 comments
Open

Panic in parse_text_lossy #141

moulins opened this issue Mar 24, 2022 · 0 comments

Comments

@moulins
Copy link

moulins commented Mar 24, 2022

The following Rust code:

let _ = rslint_parser::parse_text_lossy("var foo = (c>>10);", 0);

panics with:

'slice index starts at 8 but ends at 2', ~/.cargo/registry/src/github.com-1ecc6299db9ec823/rslint_parser-0.3.1/src/lossy_tree_sink.rs:36:13

The panicking statement is:

    fn consume_multiple_tokens(&mut self, amount: u8, kind: SyntaxKind) {
        // ...
        let len = TextSize::from(
            self.tokens[self.token_pos..amount as usize] // << HERE
                .iter()
                .map(|x| x.len)
                .sum::<usize>() as u32,
        );
        // ...
    }

This slice range looks suspicious; changing it to self.token_pos..(self.token_pos + amount as usize) seems to fix the bug.

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

No branches or pull requests

1 participant