Skip to content

Commit

Permalink
Fix buffer checks in blit_from
Browse files Browse the repository at this point in the history
  • Loading branch information
lte678 committed Oct 12, 2024
1 parent 980bdba commit 9c4c537
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ impl Canvas {
/// Blits to a rectangle with origin at `dst_point` and size according to `src_size`.
/// If the target area overlaps the boundaries of the canvas, only the drawable region is blitted.
/// `dst_point` and `src_size` are specified in pixels. `src_stride` is specified in bytes.
/// `src_stride` must be equal or larger than the actual data length.
#[allow(dead_code)]
pub(crate) fn blit_from(
&mut self,
Expand All @@ -98,16 +99,15 @@ impl Canvas {
src_format: Format,
) {
assert_eq!(
src_size.x() as usize * src_size.y() as usize,
src_bytes.len() / src_format.bytes_per_pixel(),
"Number of pixels in src_bytes does not match src_size."
src_stride * src_size.y() as usize,
src_bytes.len(),
"Number of pixels in src_bytes does not match stride and size."
);
// It might be preferable to drop src_stride as a parameter to get rid of this check.
assert_eq!(
src_size.x() as usize * src_format.bytes_per_pixel(),
src_stride,
"src_stride does not match src_size.x()"
assert!(
src_stride >= src_size.x() as usize * src_format.bytes_per_pixel(),
"src_stride must be >= than src_size.x()"
);


let dst_rect = RectI::new(dst_point, src_size);
let dst_rect = dst_rect.intersection(RectI::new(Vector2I::default(), self.size));
Expand Down

0 comments on commit 9c4c537

Please sign in to comment.