From 76906af9d70fc784de728a70e3dbda62dece5e10 Mon Sep 17 00:00:00 2001 From: "Kaleb S. KEITHLE" Date: Fri, 9 Nov 2018 11:27:11 -0500 Subject: core: fix strncpy warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since gcc-8.2.x (fedora-28 or so) gcc has been emitting warnings about buggy use of strncpy. e.g. warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length and warning: ‘strncpy’ specified bound depends on the length of the source argument Since we're copying string fragments and explicitly null terminating use memcpy to silence the warning Change-Id: I413d84b5f4157f15c99e9af3e154ce594d5bcdc1 updates: bz#1193929 Signed-off-by: Kaleb S. KEITHLEY --- libglusterfs/src/common-utils.c | 2 +- libglusterfs/src/inode.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'libglusterfs') diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 31759a3e48f..47558e76ba4 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -3113,7 +3113,7 @@ gf_canonicalize_path(char *path) while (dir) { dir_path_len = strlen(dir); - strncpy((path + path_len + 1), dir, dir_path_len); + memcpy((path + path_len + 1), dir, dir_path_len); path_len += dir_path_len + 1; dir = strtok_r(NULL, "/", &tmpstr); if (dir) { diff --git a/libglusterfs/src/inode.c b/libglusterfs/src/inode.c index b8e389ac140..a5dcac7d7e1 100644 --- a/libglusterfs/src/inode.c +++ b/libglusterfs/src/inode.c @@ -1385,7 +1385,7 @@ __inode_path(inode_t *inode, const char *name, char **bufp) if (name) { len = strlen(name); - strncpy(buf + (i - len), name, len); + memcpy(buf + (i - len), name, len); buf[i - len - 1] = '/'; i -= (len + 1); } @@ -1395,7 +1395,7 @@ __inode_path(inode_t *inode, const char *name, char **bufp) trav = __dentry_search_arbit(itrav)) { itrav = trav->parent; len = strlen(trav->name); - strncpy(buf + (i - len), trav->name, len); + memcpy(buf + (i - len), trav->name, len); buf[i - len - 1] = '/'; i -= (len + 1); } -- cgit