From 4d1d6ff64f71483a0cc00cffb2ce1b4c359a03de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?=
Date: Wed, 27 Jun 2018 20:33:30 -0700 Subject: [PATCH] maint: copy: avoid new static analyzer warnings * src/copy.c (copy_internal): Use the lint protected src_mode, rather than accessing the src_sb again. Also unconditionally populate src_sb when !x->move_mode and in lint mode. Reported by Kamil Dudka with coverity and clang analyzer. --- src/copy.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/copy.c b/src/copy.c index eccf67c..58d2f6e 100644 --- a/src/copy.c +++ b/src/copy.c @@ -1903,6 +1903,13 @@ copy_internal (char const *src_name, char const *dst_name, return false; } } +#ifdef lint + else + { + assert (x->move_mode); + memset (&src_sb, 0, sizeof src_sb); + } +#endif /* Detect the case in which the same source file appears more than once on the command line and no backup option has been selected. @@ -1910,7 +1917,7 @@ copy_internal (char const *src_name, char const *dst_name, This check is enabled only if x->src_info is non-NULL. */ if (command_line_arg && x->src_info) { - if ( ! S_ISDIR (src_sb.st_mode) + if ( ! S_ISDIR (src_mode) && x->backup_type == no_backups && seen_file (x->src_info, src_name, &src_sb)) { -- 2.9.3