ENH: fix for bug 2908 crash for empty source group name

This commit is contained in:
Bill Hoffman 2006-02-23 11:36:36 -05:00
parent 32c403f665
commit 3d617b48aa

View File

@ -21,27 +21,17 @@ inline std::vector<std::string> tokenize(const std::string& str,
bool skipEmptyTokens) bool skipEmptyTokens)
{ {
std::vector<std::string> tokens; std::vector<std::string> tokens;
if(str.size() == 0)
{
tokens.push_back("");
return tokens;
}
std::string::size_type tokstart,tokend; std::string::size_type tokstart,tokend;
if (skipEmptyTokens) tokend=0;
{
tokend=0;
}
else
{
tokend=std::string::npos;
}
do do
{ {
if (skipEmptyTokens) tokstart=str.find_first_not_of(sep,tokend);
{
tokstart=str.find_first_not_of(sep,tokend);
}
else
{
tokstart=tokend+1;
}
if (tokstart==std::string::npos) if (tokstart==std::string::npos)
{ {
break; // no more tokens break; // no more tokens
@ -56,7 +46,6 @@ inline std::vector<std::string> tokenize(const std::string& str,
tokens.push_back(str.substr(tokstart,tokend-tokstart)); tokens.push_back(str.substr(tokstart,tokend-tokstart));
} }
} while (tokend!=std::string::npos); } while (tokend!=std::string::npos);
return tokens; return tokens;
} }
@ -70,16 +59,15 @@ bool cmSourceGroupCommand::InitialPass(std::vector<std::string> const& args)
} }
std::string delimiter = "\\"; std::string delimiter = "\\";
if(m_Makefile->GetDefinition("SOURCE_GROUP_DELIMITER")) if(m_Makefile->GetDefinition("SOURCE_GROUP_DELIMITER"))
{
delimiter = m_Makefile->GetDefinition("SOURCE_GROUP_DELIMITER"); delimiter = m_Makefile->GetDefinition("SOURCE_GROUP_DELIMITER");
}
std::vector<std::string> folders = tokenize(args[0], delimiter, true); std::vector<std::string> folders = tokenize(args[0], delimiter, true);
const char *parent = NULL; const char *parent = NULL;
cmSourceGroup* sg = NULL; cmSourceGroup* sg = NULL;
for(unsigned int i=0;i<folders.size();++i) for(unsigned int i=0;i<folders.size();++i)
{ {
sg = m_Makefile->GetSourceGroup(folders[i].c_str()); sg = m_Makefile->GetSourceGroup(folders[i].c_str());
@ -90,7 +78,11 @@ bool cmSourceGroupCommand::InitialPass(std::vector<std::string> const& args)
sg = m_Makefile->GetSourceGroup(folders[i].c_str()); sg = m_Makefile->GetSourceGroup(folders[i].c_str());
parent = folders[i].c_str(); parent = folders[i].c_str();
} }
if(!sg)
{
this->SetError("Could not create or find source group");
return false;
}
// If only two arguments are given, the pre-1.8 version of the // If only two arguments are given, the pre-1.8 version of the
// command is being invoked. // command is being invoked.
if(args.size() == 2 && args[1] != "FILES") if(args.size() == 2 && args[1] != "FILES")