Skip to content

Commit

Permalink
fix UB in Bitmap::get_color_of_pattern (#57)
Browse files Browse the repository at this point in the history
remove absolutely logically wrong and necessary method
  • Loading branch information
boozook authored Sep 15, 2023
1 parent 50318b7 commit 972a7ea
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/gfx/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "playdate-graphics"
version = "0.1.1"
version = "0.1.2"
edition = "2021"

readme = "README.md"
Expand Down
15 changes: 0 additions & 15 deletions api/gfx/src/bitmap/bitmap.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use core::ffi::c_char;
use core::ffi::c_float;
use core::ffi::c_int;
use core::ffi::c_void;
use alloc::boxed::Box;

use sys::ffi::CString;
use sys::ffi::LCDColor;
use sys::ffi::LCDPattern;
use sys::ffi::LCDRect;
use sys::ffi::LCDBitmap;
pub use sys::ffi::LCDBitmapFlip as BitmapFlip;
Expand Down Expand Up @@ -298,19 +296,6 @@ impl<Api: api::Api, const FOD: bool> Bitmap<Api, FOD> {
let f = self.1.set_color_to_pattern();
unsafe { f(color as _, self.0, x, y) }
}

/// Returns 8 x 8 pattern using this bitmap.
/// `x, y` indicates the top left corner of the 8 x 8 pattern.
pub fn get_color_of_pattern<'t>(&'t self, x: c_int, y: c_int) -> &mut LCDPattern {
let mut color: LCDColor = 0;
let f = self.1.set_color_to_pattern();
unsafe { f(&mut color, self.0, x, y) }
assert!(color.is_pattern());

let ptr = color as *mut c_void as *mut u8 as *mut LCDPattern;
// TODO: check if ptr.is_null() ...
unsafe { ptr.as_mut() }.unwrap()
}
}


Expand Down

0 comments on commit 972a7ea

Please sign in to comment.