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

Update lifetimes of read_complex_string #209

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vnrst
Copy link

@vnrst vnrst commented Nov 9, 2022

The lifetimes of read_complex_string in parser.rs are weird. It returns a slice, but the lifetime of the slice is not tied to either the lifetime of self or the lifetime of the struct.

fn read_complex_string<'b>(&mut self, start: usize) -> Result<&'b str>

This could cause potential memory errors. Eg :

let sl2;
{
  let a: String = String::from("bftb\"ftbft");
  let sl: &str = &a[0..5];
  
  let mut parser = Parser::new(sl);
  parser.bump();
  sl2 = parser.read_complex_string(0);
}
println!("{:?}", sl2); // Will print garbage because the String has been dropped

This signature makes more sense and passes all tests.

fn read_complex_string(&mut self, start: usize) -> Result<&'_ str>

@gierens
Copy link

gierens commented Aug 25, 2023

Since this project is unmaintained, I forked to https://github.com/rustadopt/jzon-rs where I for example merged this PR and maintain it from now on with the community. It's also available in v0.12.5 on https://crates.io/crates/jzon

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.

None yet

2 participants