Skip to content

Commit

Permalink
Fix crash on window fill
Browse files Browse the repository at this point in the history
Fill area can be empty in one of dimensions.

Signed-off-by: Artem Senichev <[email protected]>
  • Loading branch information
artemsen committed Feb 1, 2024
1 parent 1ecc132 commit 1c52532
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/pixmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,26 @@ void pixmap_free(struct pixmap* pm)
void pixmap_fill(struct pixmap* pm, size_t x, size_t y, size_t width,
size_t height, argb_t color)
{
const size_t max_y = y + height;
const size_t template_sz = width * sizeof(argb_t);
argb_t* template = &pm->data[y * pm->width + x];
size_t max_y;
size_t template_sz;
argb_t* template;

if (width == 0 || height == 0) {
return;
}

width = min(width, pm->width - x);
height = min(height, pm->height - y);

// compose template line
template = &pm->data[y * pm->width + x];
template_sz = width * sizeof(argb_t);
for (size_t i = 0; i < width; ++i) {
template[i] = color;
}

// put template line
max_y = y + height;
for (size_t i = y + 1; i < max_y; ++i) {
memcpy(&pm->data[i * pm->width + x], template, template_sz);
}
Expand Down

0 comments on commit 1c52532

Please sign in to comment.