From 97f8cf3b7fe0583b3d43a58140d8878ab02d9d85 Mon Sep 17 00:00:00 2001 From: Tim Vanderhoek Date: Sat, 31 Jul 1999 20:40:23 +0000 Subject: [PATCH] Print an error message on illegal numerical arguments. Submitted by: bin/9349 (slightly modified) Assar Westerlund --- usr.bin/make/main.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c index 6f9f8f6ef65..6b06e687979 100644 --- a/usr.bin/make/main.c +++ b/usr.bin/make/main.c @@ -47,7 +47,7 @@ static const char copyright[] = static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94"; #endif static const char rcsid[] = - "$Id: main.c,v 1.29 1998/11/15 05:55:58 bde Exp $"; + "$Id: main.c,v 1.30 1999/03/01 06:01:05 imp Exp $"; #endif /* not lint */ /*- @@ -95,6 +95,7 @@ static const char rcsid[] = #include #include #include +#include #if __STDC__ #include #else @@ -204,11 +205,18 @@ rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) { Var_Append(MAKEFLAGS, "-B", VAR_GLOBAL); break; #ifdef REMOTE - case 'L': - maxLocal = atoi(optarg); + case 'L': { + char *endptr; + + maxLocal = strtol(optarg, &endptr, 10); + if (maxLocal < 0 || *endptr != '\0') { + errx(EX_USAGE, + "illegal argument to -L -- %s", optarg); + } Var_Append(MAKEFLAGS, "-L", VAR_GLOBAL); Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL); break; + } #endif case 'P': usePipes = FALSE; @@ -282,15 +290,22 @@ rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) { ignoreErrors = TRUE; Var_Append(MAKEFLAGS, "-i", VAR_GLOBAL); break; - case 'j': + case 'j': { + char *endptr; + forceJobs = TRUE; - maxJobs = atoi(optarg); + maxJobs = strtol(optarg, &endptr, 10); + if (maxJobs <= 0 || *endptr != '\0') { + errx(EX_USAGE, + "illegal argument to -j -- %s", optarg); + } #ifndef REMOTE maxLocal = maxJobs; #endif Var_Append(MAKEFLAGS, "-j", VAR_GLOBAL); Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL); break; + } case 'k': keepgoing = TRUE; Var_Append(MAKEFLAGS, "-k", VAR_GLOBAL);