From 619b95c7f1cd944a9bc8eb407f4510039639a74b Mon Sep 17 00:00:00 2001 From: Matheus Date: Sat, 24 Sep 2022 15:14:20 -0300 Subject: [PATCH] framebuffer: handle an edge case --- src/video/framebuffer.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/video/framebuffer.c b/src/video/framebuffer.c index 2ba8b753..25d59f27 100644 --- a/src/video/framebuffer.c +++ b/src/video/framebuffer.c @@ -18,6 +18,10 @@ static int devchecks(int fb, size_t* count, size_t offset){ size_t end = fbs[fb]->pitch * fbs[fb]->height; + if(offset >= end){ + *count = 0; + } + if(*count + offset > end) *count = end - offset; @@ -32,9 +36,9 @@ int read(int* error, int minor, void* buff, size_t count, size_t offset){ if(*error) return -1; - + memcpy(buff, fbs[minor]->address + offset, count); - + return count; } @@ -45,7 +49,7 @@ int write(int* error, int minor, void* buff, size_t count, size_t offset){ if(*error) return -1; - + memcpy(fbs[minor]->address + offset, buff, count); return count;