coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/2] seq: don't allow --equal-width option with infinite FIRST an


From: Bernhard Voelker
Subject: [PATCH 1/2] seq: don't allow --equal-width option with infinite FIRST and LAST
Date: Sat, 26 Jul 2014 20:06:14 +0200

seq(1) could not determine the width of large values toward INF
values.  Therefore, specifying -w is useless in such a case.

* src/seq.c (main): Output an error diagnostic when the -w option
is specified together with non-finite values for FIRST or LAST.
* tests/misc/seq.pl: Add tests.
* NEWS (Changes in behavior): Mention the change.
---
 NEWS              |  4 ++++
 src/seq.c         |  7 +++++++
 tests/misc/seq.pl | 20 ++++++++++++++++++++
 3 files changed, 31 insertions(+)

diff --git a/NEWS b/NEWS
index 511e626..a733360 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@ GNU coreutils NEWS                                    -*- 
outline -*-
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** Changes in behavior
+
+  seq no longer accepts non-finite values with the --equal-width option.
+
 
 * Noteworthy changes in release 8.23 (2014-07-18) [stable]
 
diff --git a/src/seq.c b/src/seq.c
index 1124358..dd9aff6 100644
--- a/src/seq.c
+++ b/src/seq.c
@@ -593,6 +593,13 @@ main (int argc, char **argv)
         }
     }
 
+  if (equal_width && (! isfinite (first.value) || ! isfinite (last.value)))
+    {
+      error (0, 0, _("infinite FIRST or LAST value may not be specified"
+                     " when printing equal width strings"));
+      usage (EXIT_FAILURE);
+    }
+
   if (first.precision == 0 && step.precision == 0 && last.precision == 0
       && 0 <= first.value && step.value == 1 && 0 <= last.value
       && !equal_width && !format_str && strlen (separator) == 1)
diff --git a/tests/misc/seq.pl b/tests/misc/seq.pl
index 9248436..25329dd 100755
--- a/tests/misc/seq.pl
+++ b/tests/misc/seq.pl
@@ -151,6 +151,26 @@ 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)]}],
+
+   # In coreutils-8.23 and earlier, these corener case were not catched.
+   ['winf1',   qw(-w inf), {EXIT => 1},
+    {ERR => "seq: infinite FIRST or LAST value may not be specified"
+            . " when printing equal width strings\n" . $try_help}],
+   ['winf2',   qw(-w 10 inf), {EXIT => 1},
+    {ERR => "seq: infinite FIRST or LAST value may not be specified"
+            . " when printing equal width strings\n" . $try_help}],
+   ['winf3',   qw(-w 1 10 inf), {EXIT => 1},
+    {ERR => "seq: infinite FIRST or LAST value may not be specified"
+            . " when printing equal width strings\n" . $try_help}],
+   ['winf4',   qw(-w -- -inf), {EXIT => 1},
+    {ERR => "seq: infinite FIRST or LAST value may not be specified"
+            . " when printing equal width strings\n" . $try_help}],
+   ['winf5',   qw(-w -- -inf 10), {EXIT => 1},
+    {ERR => "seq: infinite FIRST or LAST value may not be specified"
+            . " when printing equal width strings\n" . $try_help}],
+   ['winf6',   qw(-w -- -inf 10 20), {EXIT => 1},
+    {ERR => "seq: infinite FIRST or LAST value may not be specified"
+            . " when printing equal width strings\n" . $try_help}],
   );
 
 # Append a newline to each entry in the OUT array.
-- 
1.8.4.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]