bug-coreutils
[Top][All Lists]
Advanced

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

Re: [PATCH] better diagnostics for seq


From: Jim Meyering
Subject: Re: [PATCH] better diagnostics for seq
Date: Mon, 18 Feb 2008 18:44:34 +0100

Pádraig Brady <address@hidden> wrote:
> Steven Schubiger wrote:
>> Attached is a patch that enhances seq's diagnostics. If you agree
>> that this is the right way to go, I'll amend other files (ChangeLog,
>> etc.) as needed.
>
> Seems sensible. This is what I get on a reasonably recent tree:
>
> $ ./seq -f% 1
> ./seq: memory exhausted

Thanks again.
Here's the patch I've just pushed:

        seq: give a proper diagnostic for an invalid --format=% option
        * src/seq.c (long_double_format): Handle '%' at end of string.
        * tests/misc/seq [fmt-eos1, fmt-eos2]: New tests for the bug.
        * NEWS: Mention this.
        Reported by Pádraig Brady.

Signed-off-by: Jim Meyering <address@hidden>
---
 NEWS           |    4 ++++
 src/seq.c      |    4 ++--
 tests/misc/seq |   16 ++++++++++++----
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/NEWS b/NEWS
index 34fda4e..bc1b47d 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,10 @@ GNU coreutils NEWS                                    -*- 
outline -*-
   "rmdir --ignore-fail-on-non-empty" detects and ignores the failure
   in more cases when a directory is empty.

+  "seq -f % 1" would issue the erroneous diagnostic "seq: memory exhausted"
+  rather than reporting the invalid string format.
+  [bug introduced in coreutils-6.0]
+
 ** Improvements

   ls --color no longer outputs unnecessary escape sequences
diff --git a/src/seq.c b/src/seq.c
index 261a44b..b073fd1 100644
--- a/src/seq.c
+++ b/src/seq.c
@@ -1,5 +1,5 @@
 /* seq - print sequence of numbers to standard output.
-   Copyright (C) 1994-2007 Free Software Foundation, Inc.
+   Copyright (C) 1994-2008 Free Software Foundation, Inc.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -209,7 +209,7 @@ long_double_format (char const *fmt, struct layout *layout)
   length_modifier_offset = i;
   has_L = (fmt[i] == 'L');
   i += has_L;
-  if (! strchr ("efgaEFGA", fmt[i]))
+  if (fmt[i] == '\0' || ! strchr ("efgaEFGA", fmt[i]))
     return NULL;

   for (i++; ! (fmt[i] == '%' && fmt[i + 1] != '%'); i += (fmt[i] == '%') + 1)
diff --git a/tests/misc/seq b/tests/misc/seq
index 9c1e48f..1a153a3 100755
--- a/tests/misc/seq
+++ b/tests/misc/seq
@@ -2,7 +2,7 @@
 # -*- perl -*-
 # Test "seq".

-# Copyright (C) 1999, 2000, 2003, 2005-2007 Free Software Foundation, Inc.
+# Copyright (C) 1999, 2000, 2003, 2005-2008 Free Software Foundation, Inc.

 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -31,6 +31,7 @@ use strict;
 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;

 my $prog = 'seq';
+my $try_help = "Try `$prog --help' for more information.\n";

 my @Tests =
   (
@@ -80,9 +81,16 @@ my @Tests =

    # In coreutils-[6.0..6.9], this would mistakenly succeed and print "%Lg".
    ['fmt-c',   qw(-f %%g 1), {EXIT => 1},
-    {ERR => "seq: invalid format string: `%%g'\n"
-     . "Try `seq --help' for more information.\n"},
-],
+    {ERR => "seq: invalid format string: `%%g'\n" . $try_help }],
+
+   # In coreutils-6.9..6.10, this would fail with an erroneous diagnostic:
+   # "seq: memory exhausted".  In coreutils-6.0..6.8, it would mistakenly
+   # succeed and print a blank line.
+   ['fmt-eos1', qw(-f % 1), {EXIT => 1},
+    {ERR => "seq: invalid format string: `%'\n" . $try_help }],
+   ['fmt-eos2', qw(-f %g% 1), {EXIT => 1},
+    {ERR => "seq: invalid format string: `%g%'\n" . $try_help }],
+
   );

 # Append a newline to each entry in the OUT array.
--
1.5.4.2.124.gc4db3




reply via email to

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