Skip to content

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.

2 participants