summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Source/cmListCommand.cxx31
-rw-r--r--Tests/CMakeTests/ListTest.cmake.in8
2 files changed, 23 insertions, 16 deletions
diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx
index 1e8b7eb818..a252dc07ee 100644
--- a/Source/cmListCommand.cxx
+++ b/Source/cmListCommand.cxx
@@ -205,27 +205,30 @@ bool cmListCommand::HandleInsertCommand(std::vector<std::string> const& args)
// expand the variable
int item = atoi(args[2].c_str());
std::vector<std::string> varArgsExpanded;
- if ( !this->GetList(varArgsExpanded, listName.c_str()) && (item > 0 || item < -1))
+ if ( !this->GetList(varArgsExpanded, listName.c_str()) && item != 0)
{
cmOStringStream str;
- str << "index: " << item << " out of range (-1, 0)";
+ str << "index: " << item << " out of range (0, 0)";
this->SetError(str.str().c_str());
return false;
}
- size_t nitem = varArgsExpanded.size();
- if ( item < 0 )
+ if ( varArgsExpanded.size() != 0 )
{
- item = (int)nitem + item;
- }
- if ( item < 0 || nitem <= (size_t)item )
- {
- cmOStringStream str;
- str << "index: " << item << " out of range (-"
- << varArgsExpanded.size() << ", "
- << varArgsExpanded.size()-1 << ")";
- this->SetError(str.str().c_str());
- return false;
+ size_t nitem = varArgsExpanded.size();
+ if ( item < 0 )
+ {
+ item = (int)nitem + item;
+ }
+ if ( item < 0 || nitem <= (size_t)item )
+ {
+ cmOStringStream str;
+ str << "index: " << item << " out of range (-"
+ << varArgsExpanded.size() << ", "
+ << (varArgsExpanded.size() == 0?0:(varArgsExpanded.size()-1)) << ")";
+ this->SetError(str.str().c_str());
+ return false;
+ }
}
size_t cc;
size_t cnt = 0;
diff --git a/Tests/CMakeTests/ListTest.cmake.in b/Tests/CMakeTests/ListTest.cmake.in
index 9e72d14ead..58a8435a06 100644
--- a/Tests/CMakeTests/ListTest.cmake.in
+++ b/Tests/CMakeTests/ListTest.cmake.in
@@ -1,6 +1,6 @@
MACRO(TEST command expected)
IF("x${result}" STREQUAL "x${expected}")
- MESSAGE("TEST \"${command}\" success: \"${result}\" expected: \"${expected}\"")
+ #MESSAGE("TEST \"${command}\" success: \"${result}\" expected: \"${expected}\"")
ELSE("x${result}" STREQUAL "x${expected}")
MESSAGE(SEND_ERROR "${CMAKE_CURRENT_LIST_LINE}: TEST \"${command}\" failed: \"${result}\" expected: \"${expected}\"")
ENDIF("x${result}" STREQUAL "x${expected}")
@@ -41,7 +41,11 @@ TEST("APPEND result brad" "andy;brad")
LIST(APPEND "nonexiting_list3" brad)
SET(result "${nonexiting_list3}")
-TEST("APPEND \"nonexiting_list1\" brad" "brad")
+TEST("APPEND \"nonexiting_list3\" brad" "brad")
+
+LIST(INSERT "nonexiting_list4" 0 andy bill brad ken)
+SET(result "${nonexiting_list4}")
+TEST("APPEND \"nonexiting_list4\" andy bill brad ken" "andy;bill;brad;ken")
SET(result andy brad)
LIST(INSERT result -1 bill ken)