From e1bfb1234b6cf5527afe3db762c3a64023adf547 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Mon, 14 Oct 2019 18:08:06 +1100 Subject: [PATCH] [common] obey the destination buffer size --- VERSION | 2 +- common/src/framebuffer.c | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/VERSION b/VERSION index 038843f16..05aa7aacd 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -B1-11-g5f1d17ba1f+1 \ No newline at end of file +B1-12-g9377fdfc37+1 \ No newline at end of file diff --git a/common/src/framebuffer.c b/common/src/framebuffer.c index 7dbbb2587..d25f69308 100644 --- a/common/src/framebuffer.c +++ b/common/src/framebuffer.c @@ -40,9 +40,13 @@ bool framebuffer_read(const FrameBuffer frame, void * dst, size_t size) /* copy what we can */ uint64_t avail = frame->wp - rp; + avail = avail > size ? size : avail; + memcpy(d, frame->data + rp, avail); - rp += avail; - d += avail; + + rp += avail; + d += avail; + size -= avail; } return true; } @@ -57,9 +61,13 @@ bool framebuffer_read_fn(const FrameBuffer frame, FrameBufferReadFn fn, size_t s /* copy what we can */ uint64_t avail = frame->wp - rp; + avail = avail > size ? size : avail; + if (!fn(opaque, frame->data + rp, avail)) return false; - rp += avail; + + rp += avail; + size -= avail; } return true;