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

FixedString seems broken #165

Open
dzbarsky opened this issue Dec 25, 2021 · 0 comments
Open

FixedString seems broken #165

dzbarsky opened this issue Dec 25, 2021 · 0 comments

Comments

@dzbarsky
Copy link

This line doesn't seem correct to me:

self.buffer.resize(old_len + (self.str_len - l), 0_u8);

Let's take a closer look at the implementation:

    fn push(&mut self, value: Value) {
        let bs: String = String::from(value);
        let l = cmp::min(bs.len(), self.str_len);
        let old_len = self.buffer.len();
        self.buffer.extend_from_slice(&bs.as_bytes()[0..l]);
        self.buffer.resize(old_len + (self.str_len - l), 0_u8);
    }

In the case when the string in value is of the correct size, l = self.str_len() and we extend self.buffer with the new string, then we proceed to call self.buffer.resize(old_len, 0u8) which truncates the buffer to what it was before we did the write. We should probably resize starting at the new length, not the old one?

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