diff --git a/.github/workflows/_build-rust.yml b/.github/workflows/_build-rust.yml index d855a822..2d617544 100644 --- a/.github/workflows/_build-rust.yml +++ b/.github/workflows/_build-rust.yml @@ -89,11 +89,12 @@ jobs: - name: Code Formatting if: inputs.do-style-check run: cargo fmt --all -- --check - - name: Code Style and Doc Style + - name: "Code style: clippy" if: inputs.do-style-check - run: | - cargo doc --no-deps --document-private-items --features ${{ inputs.features }} --no-default-features - cargo clippy --all-targets --features ${{ inputs.features }} --no-default-features + run: cargo clippy --all-targets --features ${{ inputs.features }} --no-default-features + - name: "Code style: rustdoc" + if: inputs.do-style-check + run: cargo doc --no-deps --document-private-items --features ${{ inputs.features }} --no-default-features - name: Unit Test run: cargo test --verbose - name: Unit Test with Miri diff --git a/multiboot2/src/framebuffer.rs b/multiboot2/src/framebuffer.rs index 38b31793..c8ab7b75 100644 --- a/multiboot2/src/framebuffer.rs +++ b/multiboot2/src/framebuffer.rs @@ -22,7 +22,12 @@ impl<'a> Reader<'a> { Self { buffer, off: 0 } } - fn read_u8(&mut self) -> u8 { + /// Reads the next [`u8`] from the buffer and updates the internal pointer. + /// + /// # Panic + /// + /// Panics if the index is out of bounds. + fn read_next_u8(&mut self) -> u8 { let val = self .buffer .get(self.off) @@ -36,8 +41,15 @@ impl<'a> Reader<'a> { val } - fn read_u16(&mut self) -> u16 { - self.read_u8() as u16 | (self.read_u8() as u16) << 8 + /// Reads the next [`u16`] from the buffer and updates the internal pointer. + /// + /// # Panic + /// + /// Panics if the index is out of bounds. + fn read_next_u16(&mut self) -> u16 { + let u16_lo = self.read_next_u8() as u16; + let u16_hi = self.read_next_u8() as u16; + (u16_hi << 8) | u16_lo } const fn current_ptr(&self) -> *const u8 { @@ -166,7 +178,7 @@ impl FramebufferTag { // TODO we can create a struct for this and implement // DynSizedStruct for it to leverage the already existing // functionality - let num_colors = reader.read_u16(); + let num_colors = reader.read_next_u16(); let palette = { // Ensure the slice can be created without causing UB @@ -182,12 +194,12 @@ impl FramebufferTag { Ok(FramebufferType::Indexed { palette }) } FramebufferTypeId::RGB => { - let red_pos = reader.read_u8(); // These refer to the bit positions of the LSB of each field - let red_mask = reader.read_u8(); // And then the length of the field from LSB to MSB - let green_pos = reader.read_u8(); - let green_mask = reader.read_u8(); - let blue_pos = reader.read_u8(); - let blue_mask = reader.read_u8(); + let red_pos = reader.read_next_u8(); // These refer to the bit positions of the LSB of each field + let red_mask = reader.read_next_u8(); // And then the length of the field from LSB to MSB + let green_pos = reader.read_next_u8(); + let green_mask = reader.read_next_u8(); + let blue_pos = reader.read_next_u8(); + let blue_mask = reader.read_next_u8(); Ok(FramebufferType::RGB { red: FramebufferField { position: red_pos,