Skip to content

Mismatched ensure! in Element impl #24

Description

@catemiko

I found out that field len of Element have usize type actually. But it is tested against i32. Same for pos field.

#[derive(Copy, Clone, Debug)]
struct Element {
    pos: u64,
    len: usize,
}

impl Element {
    const EMPTY: Self = Self { pos: 0, len: 0 };
    const HEADER_LENGTH: usize = 4;

    #[inline]
    fn new(pos: u64, len: usize) -> Result<Self> {
        ensure!(i64::try_from(pos).is_ok(), CorruptedFileSnafu { //Why u64 testing against i64?
            msg: "element position must be less or equal to i64::MAX"
        });
        ensure!(i32::try_from(len).is_ok(), ElementTooBigSnafu); //Why usize testing against i32?

        Ok(Self { pos, len })
    }
}

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