From: Jérémie Galarneau Date: Fri, 1 Jun 2018 16:50:40 +0000 (-0400) Subject: Silence strncpy warning emitted by GCC 8 in ini parser X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=commitdiff_plain;h=9ff0b09b3a6d4469ff42e489abc78352f42ebae8;hp=97056403bdb7c18abe9c1e8e0824e3a64123c4c2 Silence strncpy warning emitted by GCC 8 in ini parser While copying 'dst len' bytes in strncpy is normally risky as the dst may not be NULL-terminated, this function ensures that the last byte of 'dst' is NULL. Therefore, this change is mostly made to silence GCC. Signed-off-by: Jérémie Galarneau --- diff --git a/src/common/config/ini.c b/src/common/config/ini.c index 34e3abf8a..41d299a19 100644 --- a/src/common/config/ini.c +++ b/src/common/config/ini.c @@ -82,7 +82,7 @@ static char* find_char_or_comment(const char* s, char c) /* Version of strncpy that ensures dest (size bytes) is null-terminated. */ static char* strncpy0(char* dest, const char* src, size_t size) { - strncpy(dest, src, size); + strncpy(dest, src, size - 1); dest[size - 1] = '\0'; return dest; }