diff options
author | Bernhard Voelker <mail@bernhard-voelker.de> | 2016-04-14 12:39:28 +0200 |
---|---|---|
committer | Bernhard Voelker <mail@bernhard-voelker.de> | 2016-04-14 12:39:28 +0200 |
commit | 9a2e8ac489d7f7b2af4e1468f6174db9106eb9e4 (patch) | |
tree | 321ec73641cd24d324fbb22f297cd042742e125b /src | |
parent | 81e589021d9c47e4fbc4284e82881a9703246476 (diff) | |
download | coreutils-9a2e8ac489d7f7b2af4e1468f6174db9106eb9e4.tar.xz |
seq: do not allow NaN arguments
* src/seq.c (isnan): Define macro.
(scan_arg): Add check if the given argument is NaN, and exit with
a proper error diagnostic in such a case.
(usage): Document it.
* tests/misc/seq.pl: Add tests.
* doc/coreutils.texi (seq invocation): Document the change.
* NEWS (Changes in behavior): Mention the change.
Diffstat (limited to 'src')
-rw-r--r-- | src/seq.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -27,11 +27,14 @@ #include "quote.h" #include "xstrtod.h" -/* Roll our own isfinite rather than using <math.h>, so that we don't +/* Roll our own isfinite/isnan rather than using <math.h>, so that we don't have to worry about linking -lm just for isfinite. */ #ifndef isfinite # define isfinite(x) ((x) * 0 == 0) #endif +#ifndef isnan +# define isnan(x) ((x) != (x)) +#endif /* The official name of this program (e.g., no 'g' prefix). */ #define PROGRAM_NAME "seq" @@ -92,7 +95,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\ +INCREMENT must not be 0; none of FIRST, INCREMENT and LAST may be NaN.\n\ "), stdout); fputs (_("\ FORMAT must be suitable for printing one argument of type 'double';\n\ @@ -144,6 +147,13 @@ scan_arg (const char *arg) usage (EXIT_FAILURE); } + if (isnan (ret.value)) + { + error (0, 0, _("invalid %s argument: %s"), quote_n (0, "not-a-number"), + quote_n (1, arg)); + usage (EXIT_FAILURE); + } + /* We don't output spaces or '+' so don't include in width */ while (isspace (to_uchar (*arg)) || *arg == '+') arg++; |