From 5d0b158f4c7b7fa506a9accec511209f68890982 Mon Sep 17 00:00:00 2001
From: =?utf8?q?P=C3=A1draig=20Brady?=
Date: Sat, 14 Feb 2009 17:20:37 +0000
Subject: [PATCH] seq: Fix equal width calculation when '.' added to last
number
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit
Issue reported by Samuel Hapák.
* src/seq.c: Account for '.' added to "last" number.
* tests/misc/seq: Add corresponding test.
* NEWS: Mention the fix.
---
NEWS | 3 +++
src/seq.c | 2 ++
tests/misc/seq | 1 +
3 files changed, 6 insertions(+)
diff --git a/NEWS b/NEWS
index a83ca66dc..9de4f256d 100644
--- a/NEWS
+++ b/NEWS
@@ -35,6 +35,9 @@ GNU coreutils NEWS -*- outline -*-
Even with this patch, on some systems, it still produces invalid output,
from 3 to at least 1026 lines long. [bug introduced in coreutils-6.11]
+ seq -w now accounts for a decimal point added to the last number
+ to correctly print all numbers to the same width.
+
wc --files0-from=FILE no longer reads all of FILE into RAM, before
processing the first file name, unless the list of names is known
to be small enough.
diff --git a/src/seq.c b/src/seq.c
index 5f9da963b..ecc72f082 100644
--- a/src/seq.c
+++ b/src/seq.c
@@ -317,6 +317,8 @@ get_default_format (operand first, operand step, operand last)
size_t last_width = last.width + (prec - last.precision);
if (last.precision && prec == 0)
last_width--; /* don't include space for '.' */
+ if (last.precision == 0 && prec)
+ last_width++; /* include space for '.' */
size_t width = MAX (first_width, last_width);
if (width <= INT_MAX)
{
diff --git a/tests/misc/seq b/tests/misc/seq
index 7f808cf6c..cd78bd164 100755
--- a/tests/misc/seq
+++ b/tests/misc/seq
@@ -64,6 +64,7 @@ my @Tests =
['eq-wid-5', qw(-w 1 .5 2), {OUT => [qw(1.0 1.5 2.0)]}],
['eq-wid-6', qw(-w +1 2), {OUT => [qw(1 2)]}],
['eq-wid-7', qw(-w " .1" " .1"), {OUT => [qw(0.1)]}],
+ ['eq-wid-8', qw(-w 9 0.5 10), {OUT => [qw(09.0 09.5 10.0)]}],
# Prior to coreutils-4.5.11, some of these were not accepted.
['fmt-1', qw(-f %2.1f 1.5 .5 2),{OUT => [qw(1.5 2.0)]}],
--
2.11.4.GIT