[git commit] ls: fix columnar output. Closes 8731

Denys Vlasenko vda.linux at googlemail.com
Sun Mar 6 16:53:11 UTC 2016


commit: https://git.busybox.net/busybox/commit/?id=ea351b97428f7dc921d5431ccac366201754fcef
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

In coreutils/ls.c, 1.19 introduced commit
2f7d9e8903029b1b5e51a15f9cb0dcb6ca17c3ac, removing the variable tabstops and
hard coding the column separation to 2 characters, but was not done correctly.
The column_width assumes a gap of 1 character, so the computed number of
columns exceeds the terminal width when many small files are encountered.

A minor problem but surprisingly annoying.

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 coreutils/ls.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/coreutils/ls.c b/coreutils/ls.c
index c484988..20bd618 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -668,7 +668,7 @@ static void display_files(struct dnode **dn, unsigned nfiles)
 			if (column_width < len)
 				column_width = len;
 		}
-		column_width += 1 +
+		column_width += 2 +
 			IF_SELINUX( ((G.all_fmt & LIST_CONTEXT) ? 33 : 0) + )
 				((G.all_fmt & LIST_INO) ? 8 : 0) +
 				((G.all_fmt & LIST_BLOCKS) ? 5 : 0);
@@ -696,8 +696,8 @@ static void display_files(struct dnode **dn, unsigned nfiles)
 			if (i < nfiles) {
 				if (column > 0) {
 					nexttab -= column;
-					printf("%*s ", nexttab, "");
-					column += nexttab + 1;
+					printf("%*s", nexttab, "");
+					column += nexttab;
 				}
 				nexttab = column + column_width;
 				column += display_single(dn[i]);


More information about the busybox-cvs mailing list