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

Segfault on &'a [&'a str] #67

Open
alfa07 opened this issue Mar 3, 2024 · 0 comments
Open

Segfault on &'a [&'a str] #67

alfa07 opened this issue Mar 3, 2024 · 0 comments

Comments

@alfa07
Copy link

alfa07 commented Mar 3, 2024

Speedy segfaults on this one:

use speedy::{Readable, Writable};

#[derive(Readable, Writable, Debug)]
struct Item<'a> {
    tags: &'a [&'a str],
    time: u32,
    value: f32,
}

// #[derive(Readable, Writable, Debug)]
// struct Item<'a> {
//     tags: Vec<&'a str>,
//     time: u32,
//     value: f32,
// }

fn main() {
    let mut buf = Vec::new();
    gen(&mut buf);
    println!("buf.len: {}", buf.len());
    let mut rbuf = buf.as_slice();
    while !rbuf.is_empty() {
        let (ritem, n) = Item::read_with_length_from_buffer(rbuf);
        println!("n: {}", n);
        println!("{:?}", ritem);
        let item = ritem.unwrap();
        println!("{:?}", item);
        rbuf = &rbuf[n..];
        println!("rbuf.len: {}", rbuf.len());
    }
}

fn gen<W: std::io::Write>(mut w: W) {
    for i in 0..10 {
        let item = Item {
            tags: &["tag1", "tag2"],
            time: i,
            value: 3.14,
        };
        item.write_to_stream(&mut w).unwrap();
    }
}

If I change tags to Vec<&'a str> it works.

❯ uname -a
Darwin MacBook-Pro.local 23.3.0 Darwin Kernel Version 23.3.0: Wed Dec 20 21:31:10 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6031 arm64

❯ rustc --version
rustc 1.75.0 (82e1608df 2023-12-21)
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