sub/draw_bmp: limit memset to available width in last slice

extends f3c1dcf7a1 for all lines not just
the last. This avoid unnecessary write every line and fixes a buffer
overflow for small enough images (for example 78x64).
This commit is contained in:
Steve Williams authored and sfan5 committed 2026-02-06 11:01:59 +01:00
1 parent 97867450ba
commit 9ccd8899ff
1 file changed
+3 -3
+3 -3
View File
@@ -485,9 +485,9 @@ static void clear_rgba_overlay(struct mp_draw_sub_cache *p)
for (int sx = 0; sx < p->s_w; sx++) {
struct slice *s = &line[sx];
// Ensure this final slice doesn't extend beyond the width of p->s_w
if (s->x1 == SLICE_W && sx == p->s_w - 1 && y == p->rgba_overlay->h - 1)
s->x1 = MPMIN(p->w - ((p->s_w - 1) * SLICE_W), s->x1);
// Ensure the last slice doesn't extend beyond the total width.
if (sx == p->s_w - 1)
s->x1 = MPMIN(p->w - (sx * SLICE_W), s->x1);
if (s->x0 <= s->x1) {
memset(px + s->x0, 0, (s->x1 - s->x0) * 4);