From: Pádraig Brady
Date: Thu, 28 Jun 2018 03:33:30 +0000 (-0700) Subject: maint: copy: avoid new static analyzer warnings X-Git-Tag: v8.30~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3246bc08a6bb3a74f0a47fb50201a75d786ba9ae;p=thirdparty%2Fcoreutils.git 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. --- diff --git a/src/copy.c b/src/copy.c index eccf67cdb2..58d2f6eb66 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)) {