]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
seq: fix misaligment with -w when no precision for start value
authorPádraig Brady <P@draigBrady.com>
Wed, 9 Jan 2013 12:23:35 +0000 (12:23 +0000)
committerPádraig Brady <P@draigBrady.com>
Sat, 26 Jan 2013 02:35:58 +0000 (02:35 +0000)
* src/seq.c (get_default_format): Also account for the case where '.'
is auto added to the start value, which is significant when the
number sequence narrows.
* tests/misc/seq.pl: Add two new tests for the failing cases.
* NEWS: Mention the fix.
Fixes http://bugs.gnu.org/13394

NEWS
src/seq.c
tests/misc/seq.pl

diff --git a/NEWS b/NEWS
index 34754bb1720e89eccbc1f13762f1814f46199e81..26939c178d10a9351c75f0f418516810cfac80a4 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -51,6 +51,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   the output numbers are properly aligned and of the correct width.
   [This bug was present in "the beginning".]
 
+  seq -w ensures correct alignment when the step value includes a precision
+  while the start value does not, and the number sequence narrows.
+  [This bug was present in "the beginning".]
+
   seq -s no longer prints an erroneous newline after the first number, and
   outputs a newline after the last number rather than a trailing separator.
   [bug introduced in coreutils-8.20]
index 22e5ec5dabec2839729430208b2885d56962ea9d..5ad5fad9485db8b1213dea64d91401404c4548c3 100644 (file)
--- a/src/seq.c
+++ b/src/seq.c
@@ -336,6 +336,8 @@ get_default_format (operand first, operand step, operand last)
             last_width--;  /* don't include space for '.' */
           if (last.precision == 0 && prec)
             last_width++;  /* include space for '.' */
+          if (first.precision == 0 && prec)
+            first_width++;  /* include space for '.' */
           size_t width = MAX (first_width, last_width);
           if (width <= INT_MAX)
             {
index 40a75714d51441dbe966be1024f73ce21f8f9612..64c62b2bc38bb2f50f9a3baad23214613b19691e 100755 (executable)
@@ -77,6 +77,10 @@ my @Tests =
    ['eq-wid-11',qw(-w -1.e-3 1),  {OUT => [qw(-0.001 00.999)]}],
    ['eq-wid-12',qw(-w -1.0e-4 1),  {OUT => [qw(-0.00010 00.99990)]}],
    ['eq-wid-13',qw(-w 999 1e3),  {OUT => [qw(0999 1000)]}],
+   # Prior to 8.21, if the start value hadn't a precision, while step did,
+   # then misalignment would occur if the sequence narrowed.
+   ['eq-wid-14',qw(-w -1 1.0 0),  {OUT => [qw(-1.0 00.0)]}],
+   ['eq-wid-15',qw(-w 10 -.1 9.9),  {OUT => [qw(10.0 09.9)]}],
 
    # 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)]}],