Skip to content

Commit 097f009

Browse files
CharlesDiascfriedt
authored andcommitted
samples: input: draw_touch_events: avoid avoid OOB writes
When CROSS_DIM doesn’t evenly divide the panel WIDTH/HEIGHT, the last tile on the right/bottom edge can extend past the display bounds. Fix by clipping the edge tiles. Signed-off-by: Charles Dias <charlesdias.cd@outlook.com>
1 parent 112871a commit 097f009

File tree

1 file changed

+9
-1
lines changed
  • samples/subsys/input/draw_touch_events/src

1 file changed

+9
-1
lines changed

samples/subsys/input/draw_touch_events/src/main.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,15 @@ static void clear_screen(void)
7070

7171
for (x = 0; x < WIDTH; x += CROSS_DIM) {
7272
for (y = 0; y < HEIGHT; y += CROSS_DIM) {
73-
display_write(display_dev, x, y, &buf_desc, buffer_cross_empty);
73+
struct display_buffer_descriptor ddesc = buf_desc;
74+
uint16_t rem_w = WIDTH - x;
75+
uint16_t rem_h = HEIGHT - y;
76+
77+
ddesc.width = MIN(buf_desc.width, rem_w);
78+
ddesc.height = MIN(buf_desc.height, rem_h);
79+
ddesc.buf_size = ddesc.width * ddesc.height * BPP;
80+
81+
display_write(display_dev, x, y, &ddesc, buffer_cross_empty);
7482
}
7583
}
7684
}

0 commit comments

Comments
 (0)