Skip to content

Commit

Permalink
Fix out of bound crash
Browse files Browse the repository at this point in the history
  • Loading branch information
hallucino committed May 26, 2017
1 parent a2a7ab1 commit 7f34f58
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/gfx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@ impl Screen {
}

pub fn putpixel_direct(&mut self, x: i32, y: i32, col: u32) {
if x >= px8::SCREEN_WIDTH as i32 || y >= px8::SCREEN_HEIGHT as i32 {

This comment has been minimized.

Copy link
@johnbatty

johnbatty May 26, 2017

Contributor

Yep, we need this check. In fact as the coords are i32 they should also be checked for negative values.

This comment has been minimized.

Copy link
@hallucino

hallucino May 26, 2017

Author Member

yep

This comment has been minimized.

Copy link
@hallucino

hallucino May 26, 2017

Author Member

I sent a CL for negative values

return;
}
self.back_buffer[Screen::pixel_offset(x, y)] = col as u8;
}

Expand All @@ -513,6 +516,10 @@ impl Screen {
return;
};

if x >= px8::SCREEN_WIDTH as i32 || y >= px8::SCREEN_HEIGHT as i32 {

This comment has been minimized.

Copy link
@johnbatty

johnbatty May 26, 2017

Contributor

We shouldn't need this check, as the clipping test above it should remove anything outside the clipping rect, and in my changes I set the default clipping rect to be the screen size, and clamp any supplied clipping rect to the screen dimensions (see Clipping::new()). I'd be interested to know if you have a test that fails without this check.

This comment has been minimized.

Copy link
@hallucino

hallucino May 26, 2017

Author Member

Right I removed that !

return;
}

let draw_col = self.color_map[(col & 0xFF) as usize];

self.back_buffer[Screen::pixel_offset(x, y)] = draw_col;
Expand Down
1 change: 0 additions & 1 deletion src/px8/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,6 @@ impl Px8New {
}

if self.configuration.lock().unwrap().show_mouse {

let mouse_x = self.players.lock().unwrap().mouse_coordinate(0);
let mouse_y = self.players.lock().unwrap().mouse_coordinate(1);

Expand Down

0 comments on commit 7f34f58

Please sign in to comment.