diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx index cbbcbb07e7..908f3b060b 100644 --- a/Source/cmListCommand.cxx +++ b/Source/cmListCommand.cxx @@ -204,6 +204,12 @@ bool cmListCommand::HandleGetCommand(std::vector const& args) this->Makefile->AddDefinition(variableName.c_str(), "NOTFOUND"); return true; } + // FIXME: Add policy to make non-existing lists an error like empty lists. + if(varArgsExpanded.empty()) + { + this->SetError("GET given empty list"); + return false; + } std::string value; size_t cc; @@ -318,7 +324,8 @@ bool cmListCommand::HandleInsertCommand(std::vector const& args) // expand the variable int item = atoi(args[2].c_str()); std::vector varArgsExpanded; - if ( !this->GetList(varArgsExpanded, listName.c_str()) && item != 0) + if((!this->GetList(varArgsExpanded, listName.c_str()) + || varArgsExpanded.empty()) && item != 0) { cmOStringStream str; str << "index: " << item << " out of range (0, 0)"; @@ -544,6 +551,12 @@ bool cmListCommand::HandleRemoveAtCommand( this->SetError("sub-command REMOVE_AT requires list to be present."); return false; } + // FIXME: Add policy to make non-existing lists an error like empty lists. + if(varArgsExpanded.empty()) + { + this->SetError("REMOVE_AT given empty list"); + return false; + } size_t cc; std::vector removed; diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 4e1660c940..1c6db390ea 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -49,6 +49,7 @@ add_RunCMake_test(ObjectLibrary) add_RunCMake_test(build_command) add_RunCMake_test(find_package) +add_RunCMake_test(list) if("${CMAKE_TEST_GENERATOR}" MATCHES "Visual Studio [^6]") add_RunCMake_test(include_external_msproject) diff --git a/Tests/RunCMake/list/CMakeLists.txt b/Tests/RunCMake/list/CMakeLists.txt new file mode 100644 index 0000000000..e8db6b05be --- /dev/null +++ b/Tests/RunCMake/list/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/list/EmptyGet0-result.txt b/Tests/RunCMake/list/EmptyGet0-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/list/EmptyGet0-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/list/EmptyGet0-stderr.txt b/Tests/RunCMake/list/EmptyGet0-stderr.txt new file mode 100644 index 0000000000..0c61b011f9 --- /dev/null +++ b/Tests/RunCMake/list/EmptyGet0-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at EmptyGet0.cmake:2 \(list\): + list GET given empty list +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\)$ diff --git a/Tests/RunCMake/list/EmptyGet0.cmake b/Tests/RunCMake/list/EmptyGet0.cmake new file mode 100644 index 0000000000..494710825f --- /dev/null +++ b/Tests/RunCMake/list/EmptyGet0.cmake @@ -0,0 +1,2 @@ +set(mylist "") +list(GET mylist 0 result) diff --git a/Tests/RunCMake/list/EmptyInsert-1-result.txt b/Tests/RunCMake/list/EmptyInsert-1-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/list/EmptyInsert-1-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/list/EmptyInsert-1-stderr.txt b/Tests/RunCMake/list/EmptyInsert-1-stderr.txt new file mode 100644 index 0000000000..0900ff9411 --- /dev/null +++ b/Tests/RunCMake/list/EmptyInsert-1-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at EmptyInsert-1.cmake:2 \(list\): + list index: -1 out of range \(0, 0\) +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\)$ diff --git a/Tests/RunCMake/list/EmptyInsert-1.cmake b/Tests/RunCMake/list/EmptyInsert-1.cmake new file mode 100644 index 0000000000..140da5d07a --- /dev/null +++ b/Tests/RunCMake/list/EmptyInsert-1.cmake @@ -0,0 +1,2 @@ +set(mylist "") +list(INSERT mylist -1 x) diff --git a/Tests/RunCMake/list/EmptyRemoveAt0-result.txt b/Tests/RunCMake/list/EmptyRemoveAt0-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/list/EmptyRemoveAt0-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/list/EmptyRemoveAt0-stderr.txt b/Tests/RunCMake/list/EmptyRemoveAt0-stderr.txt new file mode 100644 index 0000000000..b24a0ed0b8 --- /dev/null +++ b/Tests/RunCMake/list/EmptyRemoveAt0-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at EmptyRemoveAt0.cmake:2 \(list\): + list REMOVE_AT given empty list +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\)$ diff --git a/Tests/RunCMake/list/EmptyRemoveAt0.cmake b/Tests/RunCMake/list/EmptyRemoveAt0.cmake new file mode 100644 index 0000000000..d6a3e85c6a --- /dev/null +++ b/Tests/RunCMake/list/EmptyRemoveAt0.cmake @@ -0,0 +1,2 @@ +set(mylist "") +list(REMOVE_AT mylist 0) diff --git a/Tests/RunCMake/list/RunCMakeTest.cmake b/Tests/RunCMake/list/RunCMakeTest.cmake new file mode 100644 index 0000000000..555051de0c --- /dev/null +++ b/Tests/RunCMake/list/RunCMakeTest.cmake @@ -0,0 +1,5 @@ +include(RunCMake) + +run_cmake(EmptyGet0) +run_cmake(EmptyRemoveAt0) +run_cmake(EmptyInsert-1)