From: Pádraig Brady
Date: Mon, 4 May 2026 14:34:01 +0000 (+0100) Subject: ls: fix too few display columns edge case X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=13b8c11275669ebdf8cdac714eec8fb9566a4237;p=thirdparty%2Fcoreutils.git ls: fix too few display columns edge case In the edge case where the right most column would consist of only files taking 1 or 2 cells, we accounted for 3 cells, which would result in using 1 column too few. This should have been part of commit v8.24-59-ge71be1292 * src/ls.c (init_column_info): Don't account for separator in the the final column. * tests/ls/w-option.sh: Add a test case. --- diff --git a/src/ls.c b/src/ls.c index 7dbcfa75d0..fa7926f86a 100644 --- a/src/ls.c +++ b/src/ls.c @@ -993,8 +993,8 @@ static struct column_info *column_info; /* Maximum number of columns ever possible for this display. */ static size_t max_idx; -/* The minimum width of a column is 3: 1 character for the name and 2 - for the separating white space. */ +/* The minimum width of a non-final column is 3: 1 character for the name + and 2 for the separating white space. The final column is not padded. */ enum { MIN_COLUMN_WIDTH = 3 }; @@ -5276,9 +5276,10 @@ init_column_info (idx_t max_cols) for (idx_t i = 0; i < max_cols; ++i) { column_info[i].valid_len = true; - column_info[i].line_len = (i + 1) * MIN_COLUMN_WIDTH; - for (idx_t j = 0; j <= i; ++j) + column_info[i].line_len = i * MIN_COLUMN_WIDTH + 1; + for (idx_t j = 0; j < i; ++j) column_info[i].col_arr[j] = MIN_COLUMN_WIDTH; + column_info[i].col_arr[i] = 1; } } diff --git a/tests/ls/w-option.sh b/tests/ls/w-option.sh index bf10d6e578..288f9a571d 100755 --- a/tests/ls/w-option.sh +++ b/tests/ls/w-option.sh @@ -45,4 +45,21 @@ TERM=xterm ls -w0 -x --color=always || fail=1 ls -w4 -x -T0 a b > out || fail=1 compare exp out || fail=1 +# coreutils <= 9.11 could display 1 column too few +touch aa c || framework_failure_ +cat <<\EOF > exp || framework_failure_ +aa b +c +EOF +ls -w6 -x -T0 aa b c > out || fail=1 +compare exp out || fail=1 + +# coreutils <= 9.11 could display 1 column too few +cat <<\EOF > exp || framework_failure_ +aa c +b +EOF +ls -w6 -C -T0 aa b c > out || fail=1 +compare exp out || fail=1 + Exit $fail