Skip to content

Commit c860664

Browse files
andywolkmarkjcrane
authored andcommitted
[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]
1 parent 13434d5 commit c860664

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/include/test/switch_fct.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,18 @@ fctstr_safe_cpy(char *dst, char const *src, size_t num)
254254
FCT_ASSERT( num > 0 );
255255
#if defined(WIN32) && _MSC_VER >= 1400
256256
strncpy_s(dst, num, src, _TRUNCATE);
257+
dst[num - 1] = '\0';
257258
#else
258-
strncpy(dst, src, num - 1);
259+
{
260+
size_t i;
261+
262+
for (i = 0; (i < num - 1) && src[i] != '\0'; ++i) {
263+
dst[i] = src[i];
264+
}
265+
266+
dst[i] = '\0';
267+
}
259268
#endif
260-
dst[num-1] = '\0';
261269
}
262270

263271
/* Isolate the vsnprintf implementation */

0 commit comments

Comments
 (0)