summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBernhard Voelker <mail@bernhard-voelker.de>2016-04-14 12:39:28 +0200
committerBernhard Voelker <mail@bernhard-voelker.de>2016-04-14 12:39:28 +0200
commit9a2e8ac489d7f7b2af4e1468f6174db9106eb9e4 (patch)
tree321ec73641cd24d324fbb22f297cd042742e125b /src
parent81e589021d9c47e4fbc4284e82881a9703246476 (diff)
downloadcoreutils-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.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/seq.c b/src/seq.c
index 91cf625e9..de92bc278 100644
--- a/src/seq.c
+++ b/src/seq.c
@@ -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++;