From d55834c5770b5d1282682a52dfef3ad821069905 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Tue, 3 May 2022 13:27:26 -0700 Subject: modules/voronoi: slightly underscale to prevent OOB access We don't actually want to produce indices 0-width and 0-height --- src/modules/voronoi/voronoi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/modules/voronoi/voronoi.c b/src/modules/voronoi/voronoi.c index ea90389..2bd6cdc 100644 --- a/src/modules/voronoi/voronoi.c +++ b/src/modules/voronoi/voronoi.c @@ -109,8 +109,8 @@ static inline size_t voronoi_cell_origin_to_distance_idx(const voronoi_context_t { size_t x, y; - x = (cell->origin.x * .5f + .5f) * (float)ctxt->distances.width; - y = (cell->origin.y * .5f + .5f) * (float)ctxt->distances.height; + x = (cell->origin.x * .5f + .5f) * (float)(ctxt->distances.width - 1); + y = (cell->origin.y * .5f + .5f) * (float)(ctxt->distances.height - 1); return y * ctxt->distances.width + x; } @@ -269,8 +269,8 @@ static void voronoi_sample_colors(voronoi_context_t *ctxt, til_fb_fragment_t *fr voronoi_cell_t *p = &ctxt->cells[i]; int x, y; - x = (p->origin.x * .5f + .5f) * fragment->frame_width; - y = (p->origin.y * .5f + .5f) * fragment->frame_height; + x = (p->origin.x * .5f + .5f) * (fragment->frame_width - 1); + y = (p->origin.y * .5f + .5f) * (fragment->frame_height - 1); p->color = fragment->buf[y * fragment->pitch + x]; } -- cgit v1.2.3