summaryrefslogtreecommitdiff
path: root/src/fmt.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2001-08-28 08:32:51 +0000
committerJim Meyering <jim@meyering.net>2001-08-28 08:32:51 +0000
commit9ac5676264c5659004762cefd0f810451ad9ca60 (patch)
treea04847da4a467286ebfa68c779c25259e6ba0ae8 /src/fmt.c
parentda05e6a690551dc7f06408c255699c19ed90dafd (diff)
downloadcoreutils-9ac5676264c5659004762cefd0f810451ad9ca60.tar.xz
(main): Diagnose an invalid width option.
Diffstat (limited to 'src/fmt.c')
-rw-r--r--src/fmt.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/fmt.c b/src/fmt.c
index f3c39b757..f56745a47 100644
--- a/src/fmt.c
+++ b/src/fmt.c
@@ -325,13 +325,16 @@ main (register int argc, register char **argv)
if (argc > 1 && argv[1][0] == '-' && ISDIGIT (argv[1][1]))
{
+ const char *s = argv[1] + 1;
max_width = 0;
/* Old option syntax; a dash followed by one or more digits.
Move past the number. */
- for (++argv[1]; ISDIGIT (*argv[1]); ++argv[1])
+ for (; ISDIGIT (*s); ++s)
{
- /* FIXME: use strtol to detect overflow. */
- max_width = max_width * 10 + *argv[1] - '0';
+ int old_max = max_width;
+ max_width = max_width * 10 + *s - '0';
+ if (INT_MAX / 10 < old_max || max_width < old_max)
+ error (EXIT_FAILURE, 0, _("invalid width option: `%s'"), argv[1]);
}
/* Make the options we just parsed invisible to getopt. */
argv[1] = argv[0];