summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/SystemTools.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-12-12 12:51:51 (GMT)
committerBrad King <brad.king@kitware.com>2017-12-12 12:51:51 (GMT)
commit834d1878415fddb04b388b042dba7ce55a9a8a5d (patch)
tree0290041fcec80a69e59cda5f556f2b3e143b0c29 /Source/kwsys/SystemTools.cxx
parent62d8bff146b28c10c11ad7ef8114f8d06f2fcad8 (diff)
parentc6a83ecf1761eea8d0907ea9d8913fe56029a00d (diff)
downloadCMake-834d1878415fddb04b388b042dba7ce55a9a8a5d.zip
CMake-834d1878415fddb04b388b042dba7ce55a9a8a5d.tar.gz
CMake-834d1878415fddb04b388b042dba7ce55a9a8a5d.tar.bz2
Merge branch 'upstream-KWSys' into update-kwsys
* upstream-KWSys: KWSys 2017-12-12 (3ba214b7)
Diffstat (limited to 'Source/kwsys/SystemTools.cxx')
-rw-r--r--Source/kwsys/SystemTools.cxx13
1 files changed, 9 insertions, 4 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
index 50aa857..649f30b 100644
--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -4234,11 +4234,16 @@ bool SystemTools::IsSubDirectory(const std::string& cSubdir,
std::string dir = cDir;
SystemTools::ConvertToUnixSlashes(subdir);
SystemTools::ConvertToUnixSlashes(dir);
- if (subdir.size() > dir.size() && subdir[dir.size()] == '/') {
- std::string s = subdir.substr(0, dir.size());
- return SystemTools::ComparePath(s, dir);
+ if (subdir.size() <= dir.size() || dir.empty()) {
+ return false;
}
- return false;
+ bool isRootPath = *dir.rbegin() == '/'; // like "/" or "C:/"
+ size_t expectedSlashPosition = isRootPath ? dir.size() - 1u : dir.size();
+ if (subdir[expectedSlashPosition] != '/') {
+ return false;
+ }
+ std::string s = subdir.substr(0, dir.size());
+ return SystemTools::ComparePath(s, dir);
}
void SystemTools::Delay(unsigned int msec)