Skip to content

Commit 5df9dc9

Browse files
authored
Guard against negative coordinates (#4)
* Guard against negative coordinates Closes #3 * Changelog entry * Capital letter
1 parent b98f740 commit 5df9dc9

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ projects using an SPI interface.
88

99
## [Unreleased] - ReleaseDate
1010

11+
### Fixed
12+
13+
- [#4](https://github.com/jamwaffles/ssd1331/pull/4) Guard against negative pixel coordinates panicking `draw_pixel()` calls.
14+
1115
## [0.2.0-alpha.2]
1216

1317
### Changed

src/display.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,12 @@ where
372372
fn draw_pixel(&mut self, pixel: drawable::Pixel<Rgb565>) {
373373
let drawable::Pixel(pos, color) = pixel;
374374

375+
// Guard against negative values. All positive i32 values from `pos` can be represented in
376+
// the `u32`s that `set_pixel()` accepts.
377+
if pos.x < 0 || pos.y < 0 {
378+
return;
379+
}
380+
375381
self.set_pixel(
376382
(pos.x).try_into().unwrap(),
377383
(pos.y).try_into().unwrap(),

0 commit comments

Comments
 (0)