string: Tolerate SUBSTRING length exceeding end index

string SUBSTRING command now ignores length if it points
past end of string and uses end of string instead.
String SUBSTRING tests now cover more corner cases.
This commit is contained in:
Domen Vrankar
2014-11-12 23:57:16 +01:00
committed by Brad King
parent a9a040e169
commit 474bbb9dbc
4 changed files with 17 additions and 11 deletions
+2 -4
View File
@@ -711,12 +711,10 @@ bool cmStringCommand::HandleSubstringCommand(std::vector<std::string> const&
this->SetError(ostr.str());
return false;
}
int leftOverLength = intStringLength - begin;
if ( end < -1 || end > leftOverLength )
if ( end < -1 )
{
cmOStringStream ostr;
ostr << "end index: " << end << " is out of range -1 - "
<< leftOverLength;
ostr << "end index: " << end << " should be -1 or greater";
this->SetError(ostr.str());
return false;
}