From 9ff0b09b3a6d4469ff42e489abc78352f42ebae8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 1 Jun 2018 12:50:40 -0400 Subject: [PATCH] Silence strncpy warning emitted by GCC 8 in ini parser MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- src/common/config/ini.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; } -- 2.34.1