Skip to content

write_to_prefix generates panic path #200

@jettr

Description

@jettr

The write_to_prefix function is generating a panic path in our code, and I am pretty sure it is the bytes[..size].copy_from_slice(self.as_bytes()); line. The compiler doesn't have enough information to elide the slice comparison check.

If the code was written like the following, the compiler should not generate a panic path

    fn write_to_prefix<B: ByteSliceMut>(&self, mut bytes: B) -> Option<()> {
        let source = self.as_bytes();
        if bytes.len() < source.len() {
            return None;
        }

        bytes[..size].copy_from_slice(source);
        Some(())
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions