BUG: Avoid infinite loop at directory tree root

The system tools GetParentDirectory method no longer removes the root
path component.  This fixes cmSystemTools::FileExistsInParentDirectories
to not infinitely loop at when GetParentDirectory stops at the root.
This commit is contained in:
Brad King 2009-04-21 11:37:09 -04:00
parent 714d2fc04b
commit 13e454f8d3
1 changed files with 3 additions and 1 deletions

View File

@ -1104,7 +1104,8 @@ std::string cmSystemTools::FileExistsInParentDirectories(const char* fname,
SystemTools::ConvertToUnixSlashes(file);
std::string dir = directory;
SystemTools::ConvertToUnixSlashes(dir);
while ( !dir.empty() )
std::string prevDir;
while(dir != prevDir)
{
std::string path = dir + "/" + file;
if ( SystemTools::FileExists(path.c_str()) )
@ -1115,6 +1116,7 @@ std::string cmSystemTools::FileExistsInParentDirectories(const char* fname,
{
break;
}
prevDir = dir;
dir = SystemTools::GetParentDirectory(dir.c_str());
}
return "";