Skip to content

misc improvements #254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/_build-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 22 additions & 10 deletions multiboot2/src/framebuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
Loading