]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: copy: avoid new static analyzer warnings
authorPádraig Brady <P@draigBrady.com>
Thu, 28 Jun 2018 03:33:30 +0000 (20:33 -0700)
committerPádraig Brady <P@draigBrady.com>
Sun, 1 Jul 2018 01:57:43 +0000 (18:57 -0700)
* 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

index eccf67cdb2570e40ed4008fd5cf8e7cc374e7f9b..58d2f6eb66b5013540e4e2e0975ef921dd94b5ab 100644 (file)
@@ -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))
         {