bitshifter / glam-rs

A simple and fast linear algebra library for games and graphics
Apache License 2.0
1.5k stars 152 forks source link

Possible Incompleteness #501

Closed YichiZhang0613 closed 6 months ago

YichiZhang0613 commented 6 months ago

In glam-rs/src/u64/u64vec2.rs, the comment indicates that slice must be greater or equal than 2 elements long, while the code doesn't use assert! to check it. There are many similar problems in other functions.

    /// # Panics
    ///
    /// Panics if `slice` is less than 2 elements long.
    #[inline]
    #[must_use]
    pub const fn from_slice(slice: &[u64]) -> Self {
        Self::new(slice[0], slice[1])
    }
bitshifter commented 6 months ago

The slice itself asserts that the index is in bounds, so if glam did it as well here it would be checked twice.

See https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=25155bd0f0bc27cb44867d916ce5613c