don't crash if path == base_directory.

sorry I forgot to commit my changes to this file last night

svn path=/trunk/; revision=17583
This commit is contained in:
Royce Mitchell III 2005-08-28 12:08:53 +00:00
parent bb6a166390
commit cdf2899515

View file

@ -176,7 +176,9 @@ Path::RelativeFromWorkingDirectory ( const string& path )
} }
string string
Path::RelativeFromDirectory ( const string& path, const string& base_directory ) Path::RelativeFromDirectory (
const string& path,
const string& base_directory )
{ {
vector<string> vbase, vpath, vout; vector<string> vbase, vpath, vout;
Path::Split ( vbase, base_directory, true ); Path::Split ( vbase, base_directory, true );
@ -190,6 +192,8 @@ Path::RelativeFromDirectory ( const string& path, const string& base_directory )
size_t i = 0; size_t i = 0;
while ( i < vbase.size() && i < vpath.size() && vbase[i] == vpath[i] ) while ( i < vbase.size() && i < vpath.size() && vbase[i] == vpath[i] )
++i; ++i;
if ( vbase.size() == vpath.size() && i == vpath.size() )
return ".";
if ( i < vbase.size() ) if ( i < vbase.size() )
{ {
// path goes above our base directory, we will need some ..'s // path goes above our base directory, we will need some ..'s