summaryrefslogtreecommitdiffstats
path: root/SystemTools.cxx
diff options
context:
space:
mode:
authorKWSys Upstream <kwrobot@kitware.com>2017-12-12 12:08:43 (GMT)
committerBrad King <brad.king@kitware.com>2017-12-12 12:51:50 (GMT)
commitc6a83ecf1761eea8d0907ea9d8913fe56029a00d (patch)
tree43dbc1381be56133e776463fae2462d91988c6c7 /SystemTools.cxx
parent3b1bb703a2f75f26fd453e50f848b5dbd64bc169 (diff)
downloadCMake-c6a83ecf1761eea8d0907ea9d8913fe56029a00d.zip
CMake-c6a83ecf1761eea8d0907ea9d8913fe56029a00d.tar.gz
CMake-c6a83ecf1761eea8d0907ea9d8913fe56029a00d.tar.bz2
KWSys 2017-12-12 (3ba214b7)
Code extracted from: https://gitlab.kitware.com/utils/kwsys.git at commit 3ba214b7963fdd59f6f230c100550f9c5aa3deab (master). Upstream Shortlog ----------------- Gregor Jasny (1): 8e029751 SystemTools: Fix IsSubDirectory for subdirs of drive root
Diffstat (limited to 'SystemTools.cxx')
-rw-r--r--SystemTools.cxx13
1 files changed, 9 insertions, 4 deletions
diff --git a/SystemTools.cxx b/SystemTools.cxx
index 50aa857..649f30b 100644
--- a/SystemTools.cxx
+++ b/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)