From 61a1e7a7e69cc0693cdeb80b00f605c12c94708b Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Fri, 27 Oct 2017 22:54:42 +0200 Subject: [PATCH] Use casting when printing value that may be of a different type The stat struct could use whatever type for st_* fields. --- cmdline/check.c | 2 +- cmdline/mingw.h | 2 +- cmdline/parity.c | 4 ++-- cmdline/scan.c | 4 ++-- cmdline/sync.c | 8 ++++---- cmdline/touch.c | 2 +- cmdline/unix.h | 6 +++--- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cmdline/check.c b/cmdline/check.c index e266f9de..4fc21391 100644 --- a/cmdline/check.c +++ b/cmdline/check.c @@ -1473,7 +1473,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna } else if (st.st_size != 0) { unsuccesful = 1; - log_tag("error:%s:%s: Empty file error for size '%" PRIu64 "'\n", disk->name, esc_tag(file->sub, esc_buffer), st.st_size); + log_tag("error:%s:%s: Empty file error for size '%" PRIu64 "'\n", disk->name, esc_tag(file->sub, esc_buffer), (uint64_t)st.st_size); ++error; } diff --git a/cmdline/mingw.h b/cmdline/mingw.h index 4925405c..9cebf6e9 100644 --- a/cmdline/mingw.h +++ b/cmdline/mingw.h @@ -136,7 +136,7 @@ #define STAT_NSEC_INVALID -1 /* We have nano second support */ -#define STAT_NSEC(st) (st)->st_mtimensec +#define STAT_NSEC(st) ((int)(st)->st_mtimensec) /** * Generic stat information. diff --git a/cmdline/parity.c b/cmdline/parity.c index aa431355..5b38acbc 100644 --- a/cmdline/parity.c +++ b/cmdline/parity.c @@ -574,12 +574,12 @@ int parity_chsize(struct snapraid_parity_handle* handle, struct snapraid_parity* if (split->st.st_size > run) { /* LCOV_EXCL_START */ - log_fatal("Unexpected over resizing parity file '%s' to size %" PRIu64 " resulting in size %" PRIu64 ".\n", split->path, run, split->st.st_size); + log_fatal("Unexpected over resizing parity file '%s' to size %" PRIu64 " resulting in size %" PRIu64 ".\n", split->path, run, (uint64_t)split->st.st_size); return -1; /* LCOV_EXCL_STOP */ } else if (is_fixed && split->st.st_size < run) { /* LCOV_EXCL_START */ - log_fatal("Failed restoring parity file '%s' to size %" PRIu64 " resulting in size %" PRIu64 ".\n", split->path, run, split->st.st_size); + log_fatal("Failed restoring parity file '%s' to size %" PRIu64 " resulting in size %" PRIu64 ".\n", split->path, run, (uint64_t)split->st.st_size); return -1; /* LCOV_EXCL_STOP */ } else { diff --git a/cmdline/scan.c b/cmdline/scan.c index c4d86805..cd6dda6e 100644 --- a/cmdline/scan.c +++ b/cmdline/scan.c @@ -970,8 +970,8 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, ++scan->count_change; log_tag("scan:update:%s:%s: %" PRIu64 " %" PRIu64 ".%d -> %" PRIu64 " %" PRIu64 ".%d\n", disk->name, esc_tag(sub, esc_buffer), - (uint64_t)file_already_present_size, (uint64_t)file_already_present_mtime_sec, file_already_present_mtime_nsec, - (uint64_t)file->size, (uint64_t)file->mtime_sec, file->mtime_nsec + file_already_present_size, file_already_present_mtime_sec, file_already_present_mtime_nsec, + file->size, file->mtime_sec, file->mtime_nsec ); if (is_diff) { diff --git a/cmdline/sync.c b/cmdline/sync.c index 1fb1ad1d..d1dee226 100644 --- a/cmdline/sync.c +++ b/cmdline/sync.c @@ -209,10 +209,10 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta ) { log_tag("error:%u:%s:%s: Unexpected attribute change\n", i, disk->name, esc_tag(file->sub, esc_buffer)); if (handle[j].st.st_size != file->size) { - log_error("Unexpected size change at file '%s' from %" PRIu64 " to %" PRIu64 ".\n", handle[j].path, file->size, handle[j].st.st_size); + log_error("Unexpected size change at file '%s' from %" PRIu64 " to %" PRIu64 ".\n", handle[j].path, file->size, (uint64_t)handle[j].st.st_size); } else if (handle[j].st.st_mtime != file->mtime_sec || STAT_NSEC(&handle[j].st) != file->mtime_nsec) { - log_error("Unexpected time change at file '%s' from %" PRIu64 ".%d to %" PRIu64 ".%d.\n", handle[j].path, file->mtime_sec, file->mtime_nsec, (uint64_t)handle[j].st.st_mtime, (uint32_t)STAT_NSEC(&handle[j].st)); + log_error("Unexpected time change at file '%s' from %" PRIu64 ".%d to %" PRIu64 ".%d.\n", handle[j].path, file->mtime_sec, file->mtime_nsec, (uint64_t)handle[j].st.st_mtime, STAT_NSEC(&handle[j].st)); } else { log_error("Unexpected inode change from %" PRIu64 " to %" PRIu64 " at file '%s'.\n", file->inode, (uint64_t)handle[j].st.st_ino, handle[j].path); } @@ -586,10 +586,10 @@ static void sync_data_reader(struct snapraid_worker* worker, struct snapraid_tas ) { log_tag("error:%u:%s:%s: Unexpected attribute change\n", blockcur, disk->name, esc_tag(task->file->sub, esc_buffer)); if (handle->st.st_size != task->file->size) { - log_error("Unexpected size change at file '%s' from %" PRIu64 " to %" PRIu64 ".\n", handle->path, task->file->size, handle->st.st_size); + log_error("Unexpected size change at file '%s' from %" PRIu64 " to %" PRIu64 ".\n", handle->path, task->file->size, (uint64_t)handle->st.st_size); } else if (handle->st.st_mtime != task->file->mtime_sec || STAT_NSEC(&handle->st) != task->file->mtime_nsec) { - log_error("Unexpected time change at file '%s' from %" PRIu64 ".%d to %" PRIu64 ".%d.\n", handle->path, task->file->mtime_sec, task->file->mtime_nsec, (uint64_t)handle->st.st_mtime, (uint32_t)STAT_NSEC(&handle->st)); + log_error("Unexpected time change at file '%s' from %" PRIu64 ".%d to %" PRIu64 ".%d.\n", handle->path, task->file->mtime_sec, task->file->mtime_nsec, (uint64_t)handle->st.st_mtime, STAT_NSEC(&handle->st)); } else { log_error("Unexpected inode change from %" PRIu64 " to %" PRIu64 " at file '%s'.\n", task->file->inode, (uint64_t)handle->st.st_ino, handle->path); } diff --git a/cmdline/touch.c b/cmdline/touch.c index bdfbf296..c856847e 100644 --- a/cmdline/touch.c +++ b/cmdline/touch.c @@ -137,7 +137,7 @@ void state_touch(struct snapraid_state* state) /* state changed, we need to update it */ state->need_write = 1; - log_tag("touch:%s:%s: %" PRIu64 ".%d\n", disk->name, esc_tag(file->sub, esc_buffer), (uint64_t)st.st_mtime, (int)STAT_NSEC(&st)); + log_tag("touch:%s:%s: %" PRIu64 ".%d\n", disk->name, esc_tag(file->sub, esc_buffer), (uint64_t)st.st_mtime, STAT_NSEC(&st)); msg_info("touch %s\n", fmt_term(disk, file->sub, esc_buffer)); } } diff --git a/cmdline/unix.h b/cmdline/unix.h index 575a9c4d..8b190cea 100644 --- a/cmdline/unix.h +++ b/cmdline/unix.h @@ -34,11 +34,11 @@ /* Check if we have nanoseconds support */ #if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC -#define STAT_NSEC(st) (st)->st_mtim.tv_nsec /* Linux */ +#define STAT_NSEC(st) ((int)(st)->st_mtim.tv_nsec) /* Linux */ #elif HAVE_STRUCT_STAT_ST_MTIMENSEC -#define STAT_NSEC(st) (st)->st_mtimensec /* NetBSD */ +#define STAT_NSEC(st) ((int)(st)->st_mtimensec) /* NetBSD */ #elif HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC -#define STAT_NSEC(st) (st)->st_mtimespec.tv_nsec /* FreeBSD, Mac OS X */ +#define STAT_NSEC(st) ((int)(st)->st_mtimespec.tv_nsec) /* FreeBSD, Mac OS X */ #else #define STAT_NSEC(st) STAT_NSEC_INVALID #endif