summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2022-05-02 09:52:55 -0700
committerVito Caputo <vcaputo@pengaru.com>2022-05-02 09:57:48 -0700
commit51e38e69f075d99bbab13d52e3c70840bf341cc4 (patch)
treedb4f45c35a575f9c5db30e0de6be196e82cf66e3 /src/modules
parent8292d95533801b41ee4b05edc0bf296394085528 (diff)
modules/submit: fix bilerp mode out-of-bounds access
Found via -fsanitize=address, this is a quick and dirty way to prevent the OOB access without adding more conditionals, just prevent scaling the fragment dimensions to the full grid dimensions. This could be done better by reworking things a bit and putting zero at the center of the grid with a -1..+1 mapping, so rounding towards zero would land in the middle as opposed to off the start, with the existing .5f offset. But for now just fix the bug, nobody will notice the slight LCD overscan-style difference of bilerp=on vs. off due to this way.
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/submit/submit.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/modules/submit/submit.c b/src/modules/submit/submit.c
index 1f3a2ae..af2d044 100644
--- a/src/modules/submit/submit.c
+++ b/src/modules/submit/submit.c
@@ -208,15 +208,15 @@ static void draw_grid(submit_context_t *ctxt, til_fb_fragment_t *fragment)
static void draw_grid_bilerp(submit_context_t *ctxt, til_fb_fragment_t *fragment)
{
- float xscale = ((float)GRID_SIZE - 1.f) / (float)fragment->frame_width;
- float yscale = ((float)GRID_SIZE - 1.f) / (float)fragment->frame_height;
+ float xscale = ((float)GRID_SIZE - 2.f) / (float)fragment->frame_width;
+ float yscale = ((float)GRID_SIZE - 2.f) / (float)fragment->frame_height;
for (int y = 0; y < fragment->height; y++) {
for (int x = 0; x < fragment->width; x++) {
uint32_t color;
/* TODO: this could be optimized a bit! i.e. don't recompute the y for every x etc. */
- color = sample_grid_bilerp(ctxt, .5f + ((float)(fragment->x + x)) * xscale, .5f + ((float)(fragment->y + y)) * yscale);
+ color = sample_grid_bilerp(ctxt, 1.f + ((float)(fragment->x + x)) * xscale, 1.f + ((float)(fragment->y + y)) * yscale);
til_fb_fragment_put_pixel_unchecked(fragment, 0, fragment->x + x, fragment->y + y, color);
}
}
© All Rights Reserved