mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-25 06:47:19 +00:00
[common] obey the destination buffer size
This commit is contained in:
parent
9377fdfc37
commit
e1bfb1234b
@ -40,9 +40,13 @@ bool framebuffer_read(const FrameBuffer frame, void * dst, size_t size)
|
|||||||
|
|
||||||
/* copy what we can */
|
/* copy what we can */
|
||||||
uint64_t avail = frame->wp - rp;
|
uint64_t avail = frame->wp - rp;
|
||||||
|
avail = avail > size ? size : avail;
|
||||||
|
|
||||||
memcpy(d, frame->data + rp, avail);
|
memcpy(d, frame->data + rp, avail);
|
||||||
|
|
||||||
rp += avail;
|
rp += avail;
|
||||||
d += avail;
|
d += avail;
|
||||||
|
size -= avail;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -57,9 +61,13 @@ bool framebuffer_read_fn(const FrameBuffer frame, FrameBufferReadFn fn, size_t s
|
|||||||
|
|
||||||
/* copy what we can */
|
/* copy what we can */
|
||||||
uint64_t avail = frame->wp - rp;
|
uint64_t avail = frame->wp - rp;
|
||||||
|
avail = avail > size ? size : avail;
|
||||||
|
|
||||||
if (!fn(opaque, frame->data + rp, avail))
|
if (!fn(opaque, frame->data + rp, avail))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
rp += avail;
|
rp += avail;
|
||||||
|
size -= avail;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user