[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240328140512.4148825-6-arnd@kernel.org>
Date: Thu, 28 Mar 2024 15:04:49 +0100
From: Arnd Bergmann <arnd@...nel.org>
To: linux-kernel@...r.kernel.org,
Andrew Morton <akpm@...ux-foundation.org>
Cc: Arnd Bergmann <arnd@...db.de>
Subject: [PATCH 05/11] test_hexdump: avoid string truncation warning
From: Arnd Bergmann <arnd@...db.de>
gcc can warn when a string is too long to fit into the strncpy()
destination buffer, as it is here depending on the function
arguments:
inlined from 'test_hexdump_prepare_test.constprop' at /home/arnd/arm-soc/lib/test_hexdump.c:116:3:
include/linux/fortify-string.h:108:33: error: '__builtin_strncpy' output truncated copying between 0 and 32 bytes from a string of length 32 [-Werror=stringop-truncation]
108 | #define __underlying_strncpy __builtin_strncpy
| ^
include/linux/fortify-string.h:187:16: note: in expansion of macro '__underlying_strncpy'
187 | return __underlying_strncpy(p, q, size);
| ^~~~~~~~~~~~~~~~~~~~
As far as I can tell, this is harmless here because the truncation is
intentional, but using strscpy_pad() will avoid the warning since gcc
does not (yet) know about it.
Signed-off-by: Arnd Bergmann <arnd@...db.de>
---
lib/test_hexdump.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c
index b916801f23a8..c9820122af56 100644
--- a/lib/test_hexdump.c
+++ b/lib/test_hexdump.c
@@ -113,7 +113,7 @@ static void __init test_hexdump_prepare_test(size_t len, int rowsize,
*p++ = ' ';
} while (p < test + rs * 2 + rs / gs + 1);
- strncpy(p, data_a, l);
+ strscpy_pad(p, data_a, l);
p += l;
}
--
2.39.2
Powered by blists - more mailing lists