From 6b4f25a38edad9943835c074198d2e92495bebaa Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Tue, 17 Apr 2018 18:52:57 +0900 Subject: [PATCH] Fixup graphics clipping with bad bounds --- lib/graphics.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/graphics.c b/lib/graphics.c index 36cc421a..3a4209ab 100644 --- a/lib/graphics.c +++ b/lib/graphics.c @@ -43,21 +43,20 @@ static inline uint16_t max16(uint16_t a, uint16_t b) { static int _is_in_clip(gfx_context_t * ctx, int32_t y) { if (!ctx->clips) return 1; + if (y < 0 || y >= ctx->clips_size) return 1; return ctx->clips[y]; } void gfx_add_clip(gfx_context_t * ctx, int32_t x, int32_t y, int32_t w, int32_t h) { - if (ctx->clips && ctx->clips_size != ctx->height) { - free(ctx->clips); - ctx->clips = NULL; - } if (!ctx->clips) { ctx->clips = malloc(ctx->height); memset(ctx->clips, 0, ctx->height); ctx->clips_size = ctx->height; } - memset(&ctx->clips[y], 0x01, h); + for (int i = max(y,0); i < min(y+h,ctx->clips_size-1); ++i) { + ctx->clips[i] = 1; + } } void gfx_clear_clip(gfx_context_t * ctx) { @@ -130,6 +129,12 @@ void reinit_graphics_fullscreen(gfx_context_t * out) { out->size = GFX_H(out) * GFX_W(out) * GFX_B(out); + if (out->clips && out->clips_size != out->height) { + free(out->clips); + out->clips = NULL; + out->clips_size = 0; + } + if (out->buffer != out->backbuffer) { syscall_ioctl(framebuffer_fd, IO_VID_ADDR, &out->buffer); out->backbuffer = realloc(out->backbuffer, sizeof(uint32_t) * GFX_W(out) * GFX_H(out));