diff options
author | Andy Cedilnik <andy.cedilnik@kitware.com> | 2006-05-15 14:14:16 (GMT) |
---|---|---|
committer | Andy Cedilnik <andy.cedilnik@kitware.com> | 2006-05-15 14:14:16 (GMT) |
commit | ed1ea24cef3551308865fb05d97a354b852fca6c (patch) | |
tree | 265806e67a2a3672a100a3c71625c6b77c3cdc37 /Source/cmListCommand.cxx | |
parent | cb2a9be622d612c462ec901bce6a5bab7b1462d7 (diff) | |
download | CMake-ed1ea24cef3551308865fb05d97a354b852fca6c.zip CMake-ed1ea24cef3551308865fb05d97a354b852fca6c.tar.gz CMake-ed1ea24cef3551308865fb05d97a354b852fca6c.tar.bz2 |
ENH: Fix INSERT to allow inserting to empty list
Diffstat (limited to 'Source/cmListCommand.cxx')
-rw-r--r-- | Source/cmListCommand.cxx | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx index 1e8b7eb..a252dc0 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; |