From 9ac5676264c5659004762cefd0f810451ad9ca60 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 28 Aug 2001 08:32:51 +0000 Subject: (main): Diagnose an invalid width option. --- src/fmt.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/fmt.c') 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]; -- cgit v1.2.3-54-g00ecf