From f49ee08ab42def7a2fd98974a66ec9e1d396a507 Mon Sep 17 00:00:00 2001 From: chao an Date: Thu, 13 Jul 2023 16:29:57 +0800 Subject: [PATCH] drivers/sensors: fix build warning on GCC-12 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit nuttx/drivers/sensors/wtgahrs2.c: In function ‘wtgahrs2_initialize’: nuttx/drivers/sensors/wtgahrs2.c:545:22: warning: ‘%lx’ directive output may be truncated writing between 1 and 16 bytes into a region of size 14 [-Wformat-truncation=] 545 | snprintf(arg1, 16, "0x%" PRIxPTR, (uintptr_t)rtdata); | ^~~~~ nuttx/drivers/sensors/wtgahrs2.c:545:25: note: format string is defined here 545 | snprintf(arg1, 16, "0x%" PRIxPTR, (uintptr_t)rtdata); nuttx/drivers/sensors/wtgahrs2.c:545:22: note: directive argument in the range [1, 18446744073709551615] 545 | snprintf(arg1, 16, "0x%" PRIxPTR, (uintptr_t)rtdata); | ^~~~~ nuttx/drivers/sensors/wtgahrs2.c:545:3: note: ‘snprintf’ output between 4 and 19 bytes into a destination of size 16 545 | snprintf(arg1, 16, "0x%" PRIxPTR, (uintptr_t)rtdata); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: chao an --- drivers/sensors/wtgahrs2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/sensors/wtgahrs2.c b/drivers/sensors/wtgahrs2.c index 84ce9ef9b88..cbc53d55be0 100644 --- a/drivers/sensors/wtgahrs2.c +++ b/drivers/sensors/wtgahrs2.c @@ -435,7 +435,7 @@ int wtgahrs2_initialize(FAR const char *path, int devno) FAR struct wtgahrs2_sensor_s *tmp; struct termios opt; FAR char *argv[2]; - char arg1[16]; + char arg1[32]; int ret; if (!path) @@ -542,7 +542,7 @@ int wtgahrs2_initialize(FAR const char *path, int devno) wtgahrs2_sendcmd(rtdata, g_wtgahrs2_enable_sensor); - snprintf(arg1, 16, "0x%" PRIxPTR, (uintptr_t)rtdata); + snprintf(arg1, sizeof(arg1), "0x%" PRIxPTR, (uintptr_t)rtdata); argv[0] = arg1; argv[1] = NULL;