From e7b1d486e5848b6c349f7a13fabfc7d34e04eba9 Mon Sep 17 00:00:00 2001 From: Ramon Roche Date: Mon, 20 Jul 2026 14:59:39 -0700 Subject: [PATCH] fix(vectornav): replace discard swap buffer with in-place memmove MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Shifting the remaining bytes with memmove and zeroing the tail is functionally equivalent to the copy-out/zero/copy-back sequence and removes the dynamic allocation entirely, along with the unchecked malloc return. Suggested-by: Beat Küng Assisted-by: Claude:claude-fable-5 Signed-off-by: Ramon Roche --- .../ins/vectornav/libvnc/src/vn/sensors/searcher.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/drivers/ins/vectornav/libvnc/src/vn/sensors/searcher.c b/src/drivers/ins/vectornav/libvnc/src/vn/sensors/searcher.c index b37b4fc3d03..0d905dce6ac 100644 --- a/src/drivers/ins/vectornav/libvnc/src/vn/sensors/searcher.c +++ b/src/drivers/ins/vectornav/libvnc/src/vn/sensors/searcher.c @@ -74,17 +74,9 @@ void VnSearcher_discardData(char inputData[], size_t dataLength, size_t discardL else { /* Move the data to the front of the array and zero out everything else */ - /* Size of the data to move */ - size_t tmpSize = dataLength - discardLength; - /* Temporary swap buffer */ - char* tmp = (char*)malloc(sizeof(char) * tmpSize); - /* And the swap operations */ - /*memcpy_s(tmp, tmpSize, inputData + discardLength, tmpSize);*/ - memcpy(tmp, inputData + discardLength, tmpSize); - memset(inputData, 0, dataLength); - /*memcpy_s(inputData, tmpSize, tmp, tmpSize);*/ - memcpy(inputData, tmp, tmpSize); - free(tmp); + const size_t newSize = dataLength - discardLength; + memmove(inputData, inputData + discardLength, newSize); + memset(inputData + newSize, 0, discardLength); } }