summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2015-10-21 13:57:41 +0100
committerPádraig Brady <P@draigBrady.com>2015-10-21 16:13:57 +0100
commite71be1292b92b244d065873fae5a17d5e1f0a16c (patch)
treece77fb2219c8a3fce9bda19a11068c53bd025d4b /src
parent0e997681d4497fe9ba6db035909e413a5af050a9 (diff)
downloadcoreutils-e71be1292b92b244d065873fae5a17d5e1f0a16c.tar.xz
ls: fix off by one error when determining max display columns
* src/ls.c (main): Account for the first column not including a separator when calculating max_idx. * tests/ls/w-option.sh: Add a test case. * NEWS: Mention the bug fix.
Diffstat (limited to 'src')
-rw-r--r--src/ls.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/ls.c b/src/ls.c
index 0c9dc78db..ef372553f 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -1979,7 +1979,11 @@ decode_switches (int argc, char **argv)
}
}
- max_idx = MAX (1, line_length / MIN_COLUMN_WIDTH);
+ /* Determine the max possible number of display columns. */
+ max_idx = line_length / MIN_COLUMN_WIDTH;
+ /* Account for first display column not having a separator,
+ or line_lengths shorter than MIN_COLUMN_WIDTH. */
+ max_idx += line_length % MIN_COLUMN_WIDTH != 0;
filename_quoting_options = clone_quoting_options (NULL);
if (get_quoting_style (filename_quoting_options) == escape_quoting_style)