diff options
author | Chris Lattner <sabre@nondot.org> | 2005-08-08 17:25:38 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2005-08-08 17:25:38 +0000 |
commit | de0132453e2939488c2d69290bfdfb2cde94a0af (patch) | |
tree | 07308d0c6a76a6291cb6389529682d2f587d73f1 /lib/Support | |
parent | 3821e478a574b80d7f8bc96fa42731291cfccfe8 (diff) |
Reject command lines that have too many positional arguments passed (e.g.,
'opt x y'). This fixes PR493.
Patch contributed by Owen Anderson!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22705 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r-- | lib/Support/CommandLine.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index e0a8e4d51b..09038d3a5f 100644 --- a/lib/Support/CommandLine.cpp +++ b/lib/Support/CommandLine.cpp @@ -297,6 +297,10 @@ void cl::ParseCommandLineOptions(int &argc, char **argv, // Check out the positional arguments to collect information about them. unsigned NumPositionalRequired = 0; + + // Determine whether or not there are an unlimited number of positionals + bool HasUnlimitedPositionals = false; + Option *ConsumeAfterOpt = 0; if (!PositionalOpts.empty()) { if (PositionalOpts[0]->getNumOccurrencesFlag() == cl::ConsumeAfter) { @@ -331,6 +335,10 @@ void cl::ParseCommandLineOptions(int &argc, char **argv, " does not require a value!"); } UnboundedFound |= EatsUnboundedNumberOfValues(Opt); + + if (Opt->getNumOccurrencesFlag() == cl::ZeroOrMore + || Opt->getNumOccurrencesFlag() == cl::OneOrMore) + HasUnlimitedPositionals = true; } } @@ -484,7 +492,13 @@ void cl::ParseCommandLineOptions(int &argc, char **argv, << "Must specify at least " << NumPositionalRequired << " positional arguments: See: " << argv[0] << " --help\n"; ErrorParsing = true; - + } else if (!HasUnlimitedPositionals + && PositionalVals.size() > PositionalOpts.size()) { + std::cerr << ProgramName + << ": Too many positional arguments specified!\n" + << "Can specify at most " << PositionalOpts.size() + << " positional arguments: See: " << argv[0] << " --help\n"; + ErrorParsing = true; } else if (ConsumeAfterOpt == 0) { // Positional args have already been handled if ConsumeAfter is specified... |