summaryrefslogtreecommitdiffstats
path: root/Source/cmListCommand.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2012-04-17 14:32:46 (GMT)
committerBrad King <brad.king@kitware.com>2012-04-17 15:07:07 (GMT)
commit05604eb9cb7ced290af67dcc392f0a9a10e64386 (patch)
treea5f1992189bf18999e411a7a251ef6cd8c1c49f3 /Source/cmListCommand.cxx
parent3f29f755c7e633752c62c785b42e21bb388fa650 (diff)
downloadCMake-05604eb9cb7ced290af67dcc392f0a9a10e64386.zip
CMake-05604eb9cb7ced290af67dcc392f0a9a10e64386.tar.gz
CMake-05604eb9cb7ced290af67dcc392f0a9a10e64386.tar.bz2
list: Handle errors on empty lists more gracefully (#13138)
Since commit ed1ea24c (Fix INSERT to allow inserting to empty list, 2006-05-15) the list command allows insertion into an empty list at index 0. Fix rejection of insertion at non-zero (negative) indices to present an error message instead of crashing. While at it, fix the error message of the GET and REMOVE_AT operations when the list is empty to not present a bogus allowed range. Add a "RunCMake.list" test to cover failure cases on empty lists.
Diffstat (limited to 'Source/cmListCommand.cxx')
-rw-r--r--Source/cmListCommand.cxx15
1 files changed, 14 insertions, 1 deletions
diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx
index cbbcbb0..908f3b0 100644
--- a/Source/cmListCommand.cxx
+++ b/Source/cmListCommand.cxx
@@ -204,6 +204,12 @@ bool cmListCommand::HandleGetCommand(std::vector<std::string> 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<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)
+ 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<size_t> removed;