From 3506586e95447d704f34e3182783b2e0b5d3ca98 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 4 May 2026 11:37:02 -0600 Subject: [PATCH] [Unit-tests] Fix test framework error on newer compiler: 'strncpy' output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation] --- src/include/test/switch_fct.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/include/test/switch_fct.h b/src/include/test/switch_fct.h index b28feabb742..91d87bbb9ca 100644 --- a/src/include/test/switch_fct.h +++ b/src/include/test/switch_fct.h @@ -254,10 +254,18 @@ fctstr_safe_cpy(char *dst, char const *src, size_t num) FCT_ASSERT( num > 0 ); #if defined(WIN32) && _MSC_VER >= 1400 strncpy_s(dst, num, src, _TRUNCATE); + dst[num - 1] = '\0'; #else - strncpy(dst, src, num - 1); + { + size_t i; + + for (i = 0; (i < num - 1) && src[i] != '\0'; ++i) { + dst[i] = src[i]; + } + + dst[i] = '\0'; + } #endif - dst[num-1] = '\0'; } /* Isolate the vsnprintf implementation */