From 6870e088dd39a26d4ac6c92f9020e5f288b6d349 Mon Sep 17 00:00:00 2001 From: edvard Date: Tue, 17 Feb 2026 14:10:55 +0100 Subject: [PATCH] csp_buffer: memcpy only what is used in the packet This is faster in most cases size is protected with if as the user could have set invalid packet length. --- src/csp_buffer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/csp_buffer.c b/src/csp_buffer.c index ba46fe76c..884a4ae4d 100644 --- a/src/csp_buffer.c +++ b/src/csp_buffer.c @@ -160,7 +160,8 @@ csp_packet_t * csp_buffer_clone(const csp_packet_t * packet) { void csp_buffer_copy(const csp_packet_t * src, csp_packet_t * dst) { if ((NULL != src) && (NULL != dst)) { - (void)memcpy(dst, src, sizeof(csp_packet_t)); + size_t size = sizeof(csp_packet_t) - CSP_BUFFER_SIZE + src->length; + (void)memcpy(dst, src, size > sizeof(csp_packet_t) ? sizeof(csp_packet_t) : size); dst->frame_begin = (dst->header + CSP_PACKET_PADDING_BYTES) - (src->data - src->frame_begin); } }