mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 02:08:27 +08:00
cmCommandLineArgument: correctly compute next parse index
Fixes #21966 Correctly compute the next parse index for `ZeroOrOne` when it is zero, and for OneOrMore.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
(1|2)
|
@@ -0,0 +1 @@
|
||||
.*(ninja: error: unknown target 'invalid-target'|No rule to make target [`']invalid-target').*
|
@@ -209,6 +209,10 @@ function(run_BuildDir)
|
||||
${CMAKE_COMMAND} --build BuildDir-build -j)
|
||||
run_cmake_command(BuildDir--build-jobs-no-number-trailing--target ${CMAKE_COMMAND} -E chdir ..
|
||||
${CMAKE_COMMAND} --build BuildDir-build -j --target CustomTarget)
|
||||
if(RunCMake_GENERATOR MATCHES "Unix Makefiles" OR RunCMake_GENERATOR MATCHES "Ninja")
|
||||
run_cmake_command(BuildDir--build-jobs-no-number-trailing--invalid-target ${CMAKE_COMMAND} -E chdir ..
|
||||
${CMAKE_COMMAND} --build BuildDir-build -j --target invalid-target)
|
||||
endif()
|
||||
run_cmake_command(BuildDir--build--parallel-no-number ${CMAKE_COMMAND} -E chdir ..
|
||||
${CMAKE_COMMAND} --build BuildDir-build --parallel)
|
||||
run_cmake_command(BuildDir--build--parallel-no-number-trailing--target ${CMAKE_COMMAND} -E chdir ..
|
||||
|
Reference in New Issue
Block a user