summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-11-12 09:23:03 +0000
committerJim Meyering <jim@meyering.net>2003-11-12 09:23:03 +0000
commit9bdd30ba17f6a2490c670e121395a70abcca7233 (patch)
tree407adf2cc0f9de19cc31f57d8e30794f0228f449
parentb15ebcd4a7910d49180f0733b26c161edd6e175e (diff)
downloadcoreutils-9bdd30ba17f6a2490c670e121395a70abcca7233.tar.xz
(extract_dirs_from_files): Avoid useless copy operations.
This avoids a warning valgrind about memcpy with overlapping source and destination.
-rw-r--r--src/ls.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/ls.c b/src/ls.c
index c8d471f89..8243dffcb 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -2582,8 +2582,14 @@ extract_dirs_from_files (const char *dirname, int ignore_dot_and_dot_dot)
entries. */
for (i = 0, j = 0; i < files_index; i++)
- if (files[i].filetype != arg_directory)
- files[j++] = files[i];
+ {
+ if (files[i].filetype != arg_directory)
+ {
+ if (j < i)
+ files[j] = files[i];
+ ++j;
+ }
+ }
files_index = j;
}