From 11e9d893980e8e242cb6cc25b314c7fdbc31ac70 Mon Sep 17 00:00:00 2001 From: Philipp Schuster Date: Wed, 1 Jan 2025 22:38:42 +0100 Subject: [PATCH 1/3] clippy: fix --- multiboot2/src/framebuffer.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/multiboot2/src/framebuffer.rs b/multiboot2/src/framebuffer.rs index 38b31793..4cdf2c86 100644 --- a/multiboot2/src/framebuffer.rs +++ b/multiboot2/src/framebuffer.rs @@ -37,7 +37,9 @@ impl<'a> Reader<'a> { } fn read_u16(&mut self) -> u16 { - self.read_u8() as u16 | (self.read_u8() as u16) << 8 + let u16_lo = self.read_u8() as u16; + let u16_hi = self.read_u8() as u16; + (u16_hi << 8) | u16_lo } const fn current_ptr(&self) -> *const u8 { From 79f972fd5d65665c3f236b89414f1e43ec5f29cc Mon Sep 17 00:00:00 2001 From: Philipp Schuster Date: Wed, 1 Jan 2025 22:38:49 +0100 Subject: [PATCH 2/3] ci: improve clarity --- .github/workflows/_build-rust.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 From 3ce0ae2f8c0ca2468b2e40c385c2f4c12e7d2269 Mon Sep 17 00:00:00 2001 From: Philipp Schuster Date: Wed, 1 Jan 2025 22:41:26 +0100 Subject: [PATCH 3/3] framebuffer: improve clarity --- multiboot2/src/framebuffer.rs | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/multiboot2/src/framebuffer.rs b/multiboot2/src/framebuffer.rs index 4cdf2c86..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,9 +41,14 @@ impl<'a> Reader<'a> { val } - fn read_u16(&mut self) -> u16 { - let u16_lo = self.read_u8() as u16; - let u16_hi = self.read_u8() as u16; + /// 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 } @@ -168,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 @@ -184,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,