summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/common-utils.c
diff options
context:
space:
mode:
authorSunny Kumar <sunkumar@redhat.com>2017-12-20 13:30:39 +0530
committerAmar Tumballi <amarts@redhat.com>2017-12-21 04:30:28 +0000
commit4a06f851dcad6bdd730f3d2e12bd8f26709f27fe (patch)
tree0913f7cad0f460cf014c72a058bff79ca41b654b /libglusterfs/src/common-utils.c
parent8ad87e4fa5803718746e0e7315e8c9f1a37952c0 (diff)
snapshot: fix several coverity issues in glusterd-snapshot.c
This patch fixes issues 157, 426, 428, 431, 432, 437,439, 482 from [1]. [1] https://download.gluster.org/pub/gluster/glusterfs/static-analysis/master/glusterfs-coverity/2017-12-13-e255385a/html/ Change-Id: Iff9df12bd9802db29434155badb1beda045aba5b BUG: 789278 Signed-off-by: Sunny Kumar <sunkumar@redhat.com>
Diffstat (limited to 'libglusterfs/src/common-utils.c')
-rw-r--r--libglusterfs/src/common-utils.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index ef76bdfe750..46a3084fe39 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -4931,3 +4931,17 @@ get_struct_variable (int mem_num, gf_gsync_status_t *sts_val)
out:
return NULL;
}
+
+/* * Safe wrapper function for strncpy.
+ * This wrapper makes sure that when there is no null byte among the first n in
+ * source srting for strncpy function call, the string placed in dest will be
+ * null-terminated.
+ */
+
+char *
+gf_strncpy (char *dest, const char *src, const size_t dest_size)
+{
+ strncpy (dest, src, dest_size - 1);
+ dest[dest_size - 1] = '\0';
+ return dest;
+}