From 4c8760c9fb2951d897a307637a761c371e48e615 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 28 Aug 2019 10:58:56 -0400 Subject: find_path: Fix crash on empty old-style list of names Fixes: #19651 --- Source/cmFindBase.cxx | 2 +- Tests/RunCMake/find_path/EmptyOldStyle-stdout.txt | 1 + Tests/RunCMake/find_path/EmptyOldStyle.cmake | 2 ++ Tests/RunCMake/find_path/RunCMakeTest.cmake | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 Tests/RunCMake/find_path/EmptyOldStyle-stdout.txt create mode 100644 Tests/RunCMake/find_path/EmptyOldStyle.cmake diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx index e590802..42aff04 100644 --- a/Source/cmFindBase.cxx +++ b/Source/cmFindBase.cxx @@ -141,7 +141,7 @@ bool cmFindBase::ParseArguments(std::vector const& argsIn) // look for old style // FIND_*(VAR name path1 path2 ...) - if (!newStyle) { + if (!newStyle && !this->Names.empty()) { // All the short-hand arguments have been recorded as names. std::vector shortArgs = this->Names; this->Names.clear(); // clear out any values in Names diff --git a/Tests/RunCMake/find_path/EmptyOldStyle-stdout.txt b/Tests/RunCMake/find_path/EmptyOldStyle-stdout.txt new file mode 100644 index 0000000..8f21eb8 --- /dev/null +++ b/Tests/RunCMake/find_path/EmptyOldStyle-stdout.txt @@ -0,0 +1 @@ +-- VAR-NOTFOUND diff --git a/Tests/RunCMake/find_path/EmptyOldStyle.cmake b/Tests/RunCMake/find_path/EmptyOldStyle.cmake new file mode 100644 index 0000000..d78bb65 --- /dev/null +++ b/Tests/RunCMake/find_path/EmptyOldStyle.cmake @@ -0,0 +1,2 @@ +find_path(VAR ONLY_CMAKE_FIND_ROOT_PATH) +message(STATUS "${VAR}") diff --git a/Tests/RunCMake/find_path/RunCMakeTest.cmake b/Tests/RunCMake/find_path/RunCMakeTest.cmake index bf0fa89..3afbedc 100644 --- a/Tests/RunCMake/find_path/RunCMakeTest.cmake +++ b/Tests/RunCMake/find_path/RunCMakeTest.cmake @@ -1,5 +1,6 @@ include(RunCMake) +run_cmake(EmptyOldStyle) if(WIN32 OR CYGWIN) run_cmake(PrefixInPATH) endif() -- cgit v0.12