reopen 23110 thanks On 04/07/2016 11:46 AM, Ruediger Meier wrote: > I understand that this issue is not a bug. But it wouldn't be also not a > bug if coreutils would behave like BSD: > > $ seq 1 0 10 ; echo $? > seq: zero increment > 1
Ah, okay: as there's prior art in the BSDs [0], the attached proposes the same for GNU coreutils. [0] http://ftp.netbsd.org/pub/NetBSD/NetBSD-release-7/src/usr.bin/seq/seq.c Have a nice day, Berny
>From 5a7da754f7b5dca598748f5b83046507e5c91b84 Mon Sep 17 00:00:00 2001 From: Bernhard Voelker <[email protected]> Date: Thu, 7 Apr 2016 15:59:45 +0200 Subject: [PATCH] seq: do not allow 0 as increment value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * src/seq.c (main): Exit with an error diagnostic when the given step value is Zero. (usage): Document it. * doc/coreutils.texi (seq invocation): Likewise. * tests/misc/seq.pl: Add tests. * NEWS (Changes in behavior): Mention the change. Reported by ÐаÑенков Ðвгений in: http://bugs.gnu.org/23110 --- NEWS | 2 ++ doc/coreutils.texi | 2 ++ src/seq.c | 6 ++++++ tests/misc/seq.pl | 8 ++++++++ 4 files changed, 18 insertions(+) diff --git a/NEWS b/NEWS index dd3ee9c..2bdc698 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,8 @@ GNU coreutils NEWS -*- outline -*- ** Changes in behavior + seq no longer accepts 0 value as increment argument. + stat now outputs nanosecond information for time stamps even if they are out of localtime range. diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 45706bd..6b70635 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -17422,6 +17422,8 @@ even when @var{first} is larger than @var{last}. The sequence of numbers ends when the sum of the current number and @var{increment} would become greater than @var{last}, so @code{seq 1 10 10} only produces @samp{1}. +@var{increment} must not be @samp{0}; use @command{yes} to get +repeated output of a constant number. Floating-point numbers may be specified. @xref{Floating point}. The program accepts the following options. Also see @ref{Common options}. diff --git a/src/seq.c b/src/seq.c index fbb94a0..83f95d7 100644 --- a/src/seq.c +++ b/src/seq.c @@ -92,6 +92,7 @@ INCREMENT would become greater than LAST.\n\ FIRST, INCREMENT, and LAST are interpreted as floating point values.\n\ INCREMENT is usually positive if FIRST is smaller than LAST, and\n\ INCREMENT is usually negative if FIRST is greater than LAST.\n\ +INCREMENT must not be 0.\n\ "), stdout); fputs (_("\ FORMAT must be suitable for printing one argument of type 'double';\n\ @@ -634,6 +635,11 @@ main (int argc, char **argv) if (optind < argc) { + if (last.value == 0) + { + error (0, 0, _("invalid increment value: 0")); + usage (EXIT_FAILURE); + } step = last; last = scan_arg (argv[optind++]); } diff --git a/tests/misc/seq.pl b/tests/misc/seq.pl index 6564415..c4aa556 100755 --- a/tests/misc/seq.pl +++ b/tests/misc/seq.pl @@ -151,6 +151,14 @@ my @Tests = ['fast-1', qw(4), {OUT => [qw(1 2 3 4)]}], ['fast-2', qw(1 4), {OUT => [qw(1 2 3 4)]}], ['fast-3', qw(1 1 4), {OUT => [qw(1 2 3 4)]}], + + ['inc-zero-1', qw(1 0 10), {EXIT => 1}, + {ERR => "seq: invalid increment value: 0\n".$try_help}], + ['inc-zero-0', qw(0 0 0), {EXIT => 1}, + {ERR => "seq: invalid increment value: 0\n".$try_help}], + ['inc-sero-f', qw(1 0.0 10), {EXIT => 1}, + {ERR => "seq: invalid increment value: 0\n".$try_help}], + ); # Append a newline to each entry in the OUT array. -- 2.1.4
