From f0d18ddf2b0f05f6dc385b192b412f4c95228659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B6ppner?= Date: Tue, 23 Oct 2018 17:04:31 +0200 Subject: [PATCH] zdsfs: Use util_strlcpy() to copy strings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By using util_strlcpy() and correctly copying strings we can get rid of the following GCC8 compile warnings: In function ‘path_to_ds_name.constprop’, inlined from ‘zdsfs_readdir’ at zdsfs.c:282:2: zdsfs.c:78:2: warning: ‘strncpy’ specified bound 45 equals destination size [-Wstringop-truncation] strncpy(normds, path, size); ^~~~~~~~~~~~~~~~~~~~~~~~~~~ In function ‘path_to_ds_name.constprop’, inlined from ‘zdsfs_open’ at zdsfs.c:339:2: zdsfs.c:78:2: warning: ‘strncpy’ specified bound 45 equals destination size [-Wstringop-truncation] strncpy(normds, path, size); ^~~~~~~~~~~~~~~~~~~~~~~~~~~ In function ‘path_to_member_name.constprop’, inlined from ‘zdsfs_open’ at zdsfs.c:372:3: zdsfs.c:94:3: warning: ‘strncpy’ specified bound 45 equals destination size [-Wstringop-truncation] strncpy(normds, path, size); ^~~~~~~~~~~~~~~~~~~~~~~~~~~ In function ‘path_to_ds_name.constprop’, inlined from ‘zdsfs_getxattr’ at zdsfs.c:527:2: zdsfs.c:78:2: warning: ‘strncpy’ specified bound 45 equals destination size [-Wstringop-truncation] strncpy(normds, path, size); ^~~~~~~~~~~~~~~~~~~~~~~~~~~ In function ‘path_to_member_name.constprop’, inlined from ‘zdsfs_getxattr’ at zdsfs.c:547:4: zdsfs.c:94:3: warning: ‘strncpy’ specified bound 45 equals destination size [-Wstringop-truncation] strncpy(normds, path, size); ^~~~~~~~~~~~~~~~~~~~~~~~~~~ In function ‘path_to_ds_name.constprop’, inlined from ‘zdsfs_getattr.part.1’ at zdsfs.c:134:2, inlined from ‘zdsfs_getattr’: zdsfs.c:78:2: warning: ‘strncpy’ specified bound 45 equals destination size [-Wstringop-truncation] strncpy(normds, path, size); ^~~~~~~~~~~~~~~~~~~~~~~~~~~ In function ‘path_to_member_name.constprop’, inlined from ‘zdsfs_getattr.part.1’ at zdsfs.c:164:3, inlined from ‘zdsfs_getattr’: zdsfs.c:94:3: warning: ‘strncpy’ specified bound 45 equals destination size [-Wstringop-truncation] strncpy(normds, path, size); ^~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Jan Höppner --- zdsfs/zdsfs.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/zdsfs/zdsfs.c b/zdsfs/zdsfs.c index 1aac5f6b..6f75bc36 100644 --- a/zdsfs/zdsfs.c +++ b/zdsfs/zdsfs.c @@ -27,6 +27,7 @@ #endif #include "lib/libzds.h" +#include "lib/util_libc.h" #include "lib/zt_common.h" #define COMP "zdsfs: " @@ -75,11 +76,10 @@ static void path_to_ds_name(const char *path, char *normds, size_t size) if (*path == '/') ++path; - strncpy(normds, path, size); - normds[size - 1] = 0; + util_strlcpy(normds, path, size); end = strchr(normds, '/'); if (end) - *end = 0; + *end = '\0'; } static void path_to_member_name(const char *path, char *normds, size_t size) @@ -88,11 +88,10 @@ static void path_to_member_name(const char *path, char *normds, size_t size) ++path; path = strchr(path, '/'); if (!path) - normds[0] = 0; + normds[0] = '\0'; else { ++path; - strncpy(normds, path, size); - normds[size - 1] = 0; + util_strlcpy(normds, path, size); } }