summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;
}