GCC 8 warns if the destination's length is passed to strncpy,
since that could cause the destination to not be NULL-terminated.
This is not a concern for the lttng_strncpy since it checks
that the source must not be truncated. Therefore, it is safe
to simply use strcpy().
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
static inline
int lttng_strncpy(char *dst, const char *src, size_t dst_len)
{
- if (lttng_strnlen(src, dst_len) == dst_len) {
+ if (lttng_strnlen(src, dst_len) >= dst_len) {
/* Fail since copying would result in truncation. */
return -1;
}
- strncpy(dst, src, dst_len);
- /*
- * Be extra careful and put final \0 at the end after strncpy(),
- * even though we checked the length before. This makes Coverity
- * happy.
- */
- dst[dst_len - 1] = '\0';
+ strcpy(dst, src);
return 0;
}