From 6dc5dfef819cad69d6d4b4c1c305efa74236ad84 Mon Sep 17 00:00:00 2001 From: Xavi Hernandez Date: Fri, 6 Jul 2018 20:23:35 +0200 Subject: Fix compile warnings This patch fixes compile warnings that appear with newer compilers. The solution applied is only to remove the warnings, but it doesn't always solve the problem in the best way. It assumes that the problem will never happen, as the previous code assumed. Change-Id: I6e8470d6c2e2dbd3bd7d324b5fd2f92ffdc3d6ec updates: bz#1193929 Signed-off-by: Xavi Hernandez --- libglusterfs/src/common-utils.c | 5 +++-- libglusterfs/src/statedump.c | 17 +++++++++++------ libglusterfs/src/statedump.h | 15 ++++++++++----- 3 files changed, 24 insertions(+), 13 deletions(-) (limited to 'libglusterfs') diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 60725769096..09f0caa7e8a 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -3061,8 +3061,9 @@ gf_canonicalize_path (char *path) strncpy ((path + path_len + 1), dir, dir_path_len); path_len += dir_path_len + 1; dir = strtok_r (NULL, "/", &tmpstr); - if (dir) - strncpy ((path + path_len), "/", 1); + if (dir) { + path[path_len] = '/'; + } } path[path_len] = '\0'; ret = 0; diff --git a/libglusterfs/src/statedump.c b/libglusterfs/src/statedump.c index 874326f44ce..21a916ea6b8 100644 --- a/libglusterfs/src/statedump.c +++ b/libglusterfs/src/statedump.c @@ -858,11 +858,16 @@ gf_proc_dump_info (int signum, glusterfs_ctx_t *ctx) if (ret < 0) goto out; - snprintf (path, sizeof (path), "%s/%s.%d.dump.%"PRIu64, - ((dump_options.dump_path != NULL)?dump_options.dump_path: - ((ctx->statedump_path != NULL)?ctx->statedump_path: - DEFAULT_VAR_RUN_DIRECTORY)), brick_name, getpid(), - (uint64_t) time (NULL)); + ret = snprintf (path, sizeof (path), "%s/%s.%d.dump.%"PRIu64, + ((dump_options.dump_path != NULL) + ? dump_options.dump_path + : ((ctx->statedump_path != NULL) + ? ctx->statedump_path + : DEFAULT_VAR_RUN_DIRECTORY)), + brick_name, getpid(), (uint64_t) time (NULL)); + if ((ret < 0) || (ret >= sizeof(path))) { + goto out; + } snprintf (tmp_dump_name, PATH_MAX, "%s/dumpXXXXXX", ((dump_options.dump_path != NULL)?dump_options.dump_path: @@ -939,10 +944,10 @@ gf_proc_dump_info (int signum, glusterfs_ctx_t *ctx) timestr); ret = sys_write (gf_dump_fd, sign_string, strlen (sign_string)); -out: if (gf_dump_fd != -1) gf_proc_dump_close (); sys_rename (tmp_dump_name, path); +out: GF_FREE (dump_options.dump_path); dump_options.dump_path = NULL; gf_proc_dump_unlock (); diff --git a/libglusterfs/src/statedump.h b/libglusterfs/src/statedump.h index 0a7a97e10d4..92246e1e37e 100644 --- a/libglusterfs/src/statedump.h +++ b/libglusterfs/src/statedump.h @@ -41,13 +41,18 @@ __attribute__ ((__format__ (__printf__, 3, 4))) static inline void _gf_proc_dump_build_key (char *key, const char *prefix, const char *fmt, ...) { - char buf[GF_DUMP_MAX_BUF_LEN] = { 0, }; va_list ap; + int32_t len; - va_start(ap, fmt); - vsnprintf(buf, GF_DUMP_MAX_BUF_LEN, fmt, ap); - va_end(ap); - snprintf(key, GF_DUMP_MAX_BUF_LEN, "%s.%s", prefix, buf); + len = snprintf(key, GF_DUMP_MAX_BUF_LEN, "%s.", prefix); + if (len >= 0) { + va_start(ap, fmt); + len = vsnprintf(key + len, GF_DUMP_MAX_BUF_LEN - len, fmt, ap); + va_end(ap); + } + if (len < 0) { + *key = 0; + } } #define gf_proc_dump_build_key(key, key_prefix, fmt...) \ -- cgit