diff options
author | Robert Bozzetto <towrang@outlook.com> | 2020-10-16 01:00:47 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-10-16 12:49:28 (GMT) |
commit | 747f80fe82b6045fca006ece601b2189bc547aac (patch) | |
tree | 01ab89f6e9a4eccc3bd1d00d9baef73c89be5e95 | |
parent | b1d9a25f35a22f41b2c1b87725f091936711a28c (diff) | |
download | CMake-747f80fe82b6045fca006ece601b2189bc547aac.zip CMake-747f80fe82b6045fca006ece601b2189bc547aac.tar.gz CMake-747f80fe82b6045fca006ece601b2189bc547aac.tar.bz2 |
separate_arguments: Fix crash on *_COMMAND with no arguments
Fixes: #21320
4 files changed, 20 insertions, 0 deletions
diff --git a/Source/cmSeparateArgumentsCommand.cxx b/Source/cmSeparateArgumentsCommand.cxx index 7e501a2..52b1a44 100644 --- a/Source/cmSeparateArgumentsCommand.cxx +++ b/Source/cmSeparateArgumentsCommand.cxx @@ -80,6 +80,11 @@ bool cmSeparateArgumentsCommand(std::vector<std::string> const& args, return false; } + if (unparsedArguments.empty()) { + status.GetMakefile().AddDefinition(var, {}); + return true; + } + std::string& command = unparsedArguments.front(); if (command.empty()) { diff --git a/Tests/RunCMake/separate_arguments/NativeCommand.cmake b/Tests/RunCMake/separate_arguments/NativeCommand.cmake index 1cb009e..0051a79 100644 --- a/Tests/RunCMake/separate_arguments/NativeCommand.cmake +++ b/Tests/RunCMake/separate_arguments/NativeCommand.cmake @@ -17,3 +17,8 @@ if(NOT "${native_out}" STREQUAL "${native_exp}") message(FATAL_ERROR "separate_arguments native-style failed. " "Expected\n [${native_exp}]\nbut got\n [${native_out}]\n") endif() + +separate_arguments(empty_out NATIVE_COMMAND) +if(NOT empty_out STREQUAL "") + message(FATAL_ERROR "separate_arguments native-style failed on no arguments") +endif() diff --git a/Tests/RunCMake/separate_arguments/UnixCommand.cmake b/Tests/RunCMake/separate_arguments/UnixCommand.cmake index 0b5767a..c56cd63 100644 --- a/Tests/RunCMake/separate_arguments/UnixCommand.cmake +++ b/Tests/RunCMake/separate_arguments/UnixCommand.cmake @@ -6,3 +6,8 @@ if(NOT "${unix_out}" STREQUAL "${unix_exp}") message(FATAL_ERROR "separate_arguments unix-style failed. " "Expected\n [${unix_exp}]\nbut got\n [${unix_out}]\n") endif() + +separate_arguments(empty_out UNIX_COMMAND) +if(NOT empty_out STREQUAL "") + message(FATAL_ERROR "separate_arguments unix-style failed on no arguments") +endif() diff --git a/Tests/RunCMake/separate_arguments/WindowsCommand.cmake b/Tests/RunCMake/separate_arguments/WindowsCommand.cmake index 86aa14a..cd07494 100644 --- a/Tests/RunCMake/separate_arguments/WindowsCommand.cmake +++ b/Tests/RunCMake/separate_arguments/WindowsCommand.cmake @@ -6,3 +6,8 @@ if(NOT "${windows_out}" STREQUAL "${windows_exp}") message(FATAL_ERROR "separate_arguments windows-style failed. " "Expected\n [${windows_exp}]\nbut got\n [${windows_out}]\n") endif() + +separate_arguments(empty_out WINDOWS_COMMAND) +if(NOT empty_out STREQUAL "") + message(FATAL_ERROR "separate_arguments windows-style failed on no arguments") +endif() |