On 06/18/2014 01:03 PM, Pádraig Brady wrote:
> On 06/18/2014 10:41 AM, Rasmus Villemoes wrote:
>> $ ./seq --version | head -1
>> seq (GNU coreutils) 8.22.119-8a51b
>>
>> ./seq -0 n works fine when n is a single digit:
>>
>> $ ./seq --separator=, -0 5
>> -0,1,2,3,4,5
>>
>> But something weird happens when one uses a number >= 10:
>>
>> $ ./seq --separator=, -0 10
>> -0,-1,-2,-3,-4,-5,-6,-7,-8,-9,.0,.1,.2,.3,.4,.5,.6,.7,.8,.9,/0,/1,/2,/3,/4,/5,/6,/7,/8,/9,00,01,02,03,04,05,06,07,08,09,10
>>
>> [It also happens without the --separator; I just use that to save
>> vertical space.] This smells of ASCII, and looking at the code, the
>> problem is very likely to be the seq_fast/incr functions. I don't know
>> what the simplest fix is, though.
> 
> Ouch. I see the issue. Fix on the way...

Fast path avoidance logic updated in the attached.

thanks!
Pádraig.

>From a0027968594781b5421abe0ec9636d6653d2cc9f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Wed, 18 Jun 2014 14:30:57 +0100
Subject: [PATCH] seq: fix incorrect output with start or end of -0

* src/seq.c (main): Avoid seq_fast() with a start or end of -0.
* tests/misc/seq.pl: Add test cases.
* NEWS: Mention the fix.
Fixes http://bugs.gnu.org/17800
---
 NEWS              |    3 +++
 src/seq.c         |    2 +-
 tests/misc/seq.pl |    3 +++
 3 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/NEWS b/NEWS
index 5d1fe99..77286f8 100644
--- a/NEWS
+++ b/NEWS
@@ -74,6 +74,9 @@ GNU coreutils NEWS                                    -*- outline -*-
   ptx now consistently trims whitespace when processing multiple files.
   [This bug was present in "the beginning".]
 
+  seq again generates correct output with start or end values = -0.
+  [bug introduced in coreutils-8.20.]
+
   shuf --repeat no longer dumps core if the input is empty.
   [bug introduced with the --repeat feature in coreutils-8.22]
 
diff --git a/src/seq.c b/src/seq.c
index 8fced4a..1124358 100644
--- a/src/seq.c
+++ b/src/seq.c
@@ -604,7 +604,7 @@ main (int argc, char **argv)
       if (asprintf (&s2, "%0.Lf", last.value) < 0)
         xalloc_die ();
 
-      if (seq_fast (s1, s2))
+      if (*s1 != '-' && *s2 != '-' && seq_fast (s1, s2))
         {
           IF_LINT (free (s1));
           IF_LINT (free (s2));
diff --git a/tests/misc/seq.pl b/tests/misc/seq.pl
index 329e1df..9248436 100755
--- a/tests/misc/seq.pl
+++ b/tests/misc/seq.pl
@@ -143,6 +143,9 @@ my @Tests =
    ['not-fast-1', qw(1 3 1), {OUT => [qw(1)]}],
    ['not-fast-2', qw(1 1 4.2), {OUT => [qw(1 2 3 4)]}],
    ['not-fast-3', qw(1 1 0)],
+   # In 8.20..8.22 a start or end of -0 was broken
+   ['not-fast-4', qw(-0 10), {OUT => [qw(-0 1 2 3 4 5 6 7 8 9 10)]}],
+   ['not-fast-5', qw(1 -0)],
 
    # Ensure the correct parameters are passed to the fast path
    ['fast-1', qw(4), {OUT => [qw(1 2 3 4)]}],
-- 
1.7.7.6

Reply via email to