[llvm-commits] CVS: llvm/lib/Support/CommandLine.cpp
Chris Lattner
lattner at cs.uiuc.edu
Mon Aug 8 10:25:50 PDT 2005
Changes in directory llvm/lib/Support:
CommandLine.cpp updated: 1.61 -> 1.62
---
Log message:
Reject command lines that have too many positional arguments passed (e.g.,
'opt x y'). This fixes PR493: http://llvm.cs.uiuc.edu/PR493 .
Patch contributed by Owen Anderson!
---
Diffs of the changes: (+15 -1)
CommandLine.cpp | 16 +++++++++++++++-
1 files changed, 15 insertions(+), 1 deletion(-)
Index: llvm/lib/Support/CommandLine.cpp
diff -u llvm/lib/Support/CommandLine.cpp:1.61 llvm/lib/Support/CommandLine.cpp:1.62
--- llvm/lib/Support/CommandLine.cpp:1.61 Fri May 13 14:49:09 2005
+++ llvm/lib/Support/CommandLine.cpp Mon Aug 8 12:25:38 2005
@@ -297,6 +297,10 @@
// 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 @@
" does not require a value!");
}
UnboundedFound |= EatsUnboundedNumberOfValues(Opt);
+
+ if (Opt->getNumOccurrencesFlag() == cl::ZeroOrMore
+ || Opt->getNumOccurrencesFlag() == cl::OneOrMore)
+ HasUnlimitedPositionals = true;
}
}
@@ -484,7 +492,13 @@
<< "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...
More information about the llvm-commits
mailing list