summaryrefslogtreecommitdiff
path: root/Source/cmCommandLineArgument.h
diff options
context:
space:
mode:
authorRobert Maynard <rmaynard@nvidia.com>2021-03-24 14:03:23 -0400
committerRobert Maynard <rmaynard@nvidia.com>2021-03-26 09:34:46 -0400
commit79d7bcaf4029ce7b78abfcbcaf8cd1a09a172437 (patch)
treeb482fd81880a5611779034850b37dc56f971cc4f /Source/cmCommandLineArgument.h
parentfb91e21e469edd827714011ecabdee587c72811f (diff)
downloadcmake-79d7bcaf4029ce7b78abfcbcaf8cd1a09a172437.tar.gz
cmCommandLineArgument: correctly compute next parse index
Fixes #21966 Correctly compute the next parse index for `ZeroOrOne` when it is zero, and for OneOrMore.
Diffstat (limited to 'Source/cmCommandLineArgument.h')
-rw-r--r--Source/cmCommandLineArgument.h14
1 files changed, 9 insertions, 5 deletions
diff --git a/Source/cmCommandLineArgument.h b/Source/cmCommandLineArgument.h
index cbedf0a9c0..495dc69791 100644
--- a/Source/cmCommandLineArgument.h
+++ b/Source/cmCommandLineArgument.h
@@ -76,8 +76,9 @@ struct cmCommandLineArgument
} else if (this->Type == Values::One || this->Type == Values::ZeroOrOne) {
if (input.size() == this->Name.size()) {
- ++index;
- if (index >= allArgs.size() || allArgs[index][0] == '-') {
+ auto nextValueIndex = index + 1;
+ if (nextValueIndex >= allArgs.size() ||
+ allArgs[nextValueIndex][0] == '-') {
if (this->Type == Values::ZeroOrOne) {
parseState =
this->StoreCall(std::string{}, std::forward<CallState>(state)...)
@@ -87,10 +88,11 @@ struct cmCommandLineArgument
parseState = ParseMode::ValueError;
}
} else {
- parseState =
- this->StoreCall(allArgs[index], std::forward<CallState>(state)...)
+ parseState = this->StoreCall(allArgs[nextValueIndex],
+ std::forward<CallState>(state)...)
? ParseMode::Valid
: ParseMode::Invalid;
+ index = nextValueIndex;
}
} else {
// parse the string to get the value
@@ -133,7 +135,8 @@ struct cmCommandLineArgument
} else if (this->Type == Values::OneOrMore) {
if (input.size() == this->Name.size()) {
auto nextValueIndex = index + 1;
- if (nextValueIndex >= allArgs.size() || allArgs[index + 1][0] == '-') {
+ if (nextValueIndex >= allArgs.size() ||
+ allArgs[nextValueIndex][0] == '-') {
parseState = ParseMode::ValueError;
} else {
std::string buffer = allArgs[nextValueIndex++];
@@ -145,6 +148,7 @@ struct cmCommandLineArgument
this->StoreCall(buffer, std::forward<CallState>(state)...)
? ParseMode::Valid
: ParseMode::Invalid;
+ index = (nextValueIndex - 1);
}
}
}