From e02290d2a4529de8bfee6aaeaa180c3179ca399c Mon Sep 17 00:00:00 2001 From: Dom Cobley Date: Mon, 15 Jan 2024 15:12:05 +0000 Subject: [PATCH] vcgencmd: Avoid compiler complaints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In file included from /usr/include/string.h:535, from /<>/vcgencmd/vcgencmd.c:34: In function ‘strncat’, inlined from ‘gencmd’ at /<>/vcgencmd/vcgencmd.c:109:4, inlined from ‘main’ at /<>/vcgencmd/vcgencmd.c:152:14: /usr/include/arm-linux-gnueabihf/bits/string_fortified.h:138:10: warning: ‘__builtin___strncat_chk’ specified bound 1024 equals destination size [-Wstringop-overflow=] 138 | return __builtin___strncat_chk (__dest, __src, __len, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 139 | __glibc_objsize (__dest)); | ~~~~~~~~~~~~~~~~~~~~~~~~~ can be seen with "gcc -O2 -Wall" --- vcgencmd/vcgencmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vcgencmd/vcgencmd.c b/vcgencmd/vcgencmd.c index 0c2b23d..5fc3a33 100644 --- a/vcgencmd/vcgencmd.c +++ b/vcgencmd/vcgencmd.c @@ -105,8 +105,8 @@ static unsigned gencmd(int file_desc, const char *command, char *result, int res p[0] = i*sizeof *p; // actual size mbox_property(file_desc, p); - result[0] = 0; - strncat(result, (const char *)(p+6), result_len); + memcpy(result, p+6, result_len); + result[result_len -1] = '\0'; return p[5]; }