diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2022-05-03 13:27:26 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2022-05-03 13:27:26 -0700 |
commit | d55834c5770b5d1282682a52dfef3ad821069905 (patch) | |
tree | 1aed91c2b2f2e1464355e2daab2401305e6d8ce2 /src/modules | |
parent | 42e740d4fd63b7b02cc855c2601d87ebeb9236db (diff) |
modules/voronoi: slightly underscale to prevent OOB access
We don't actually want to produce indices 0-width and 0-height
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/voronoi/voronoi.c | 8 |
1 files changed, 4 insertions, 4 deletions
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]; } |