diff options
author | Brad King <brad.king@kitware.com> | 2021-10-27 15:21:46 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-10-27 15:21:46 (GMT) |
commit | 848eeba483bef0cfeeef78ae77dc3c9a7327b8ea (patch) | |
tree | 3f8066f2905e9c1deb97f3f48db165edf8017289 /Source/kwsys/Directory.cxx | |
parent | a956be484783a991dbda3b14f676538d5f0b17bd (diff) | |
parent | 6015a898d463fc321187ae346155654d55393a4c (diff) | |
download | CMake-848eeba483bef0cfeeef78ae77dc3c9a7327b8ea.zip CMake-848eeba483bef0cfeeef78ae77dc3c9a7327b8ea.tar.gz CMake-848eeba483bef0cfeeef78ae77dc3c9a7327b8ea.tar.bz2 |
Merge branch 'upstream-KWSys' into update-kwsys
# By KWSys Upstream
* upstream-KWSys:
KWSys 2021-10-27 (e19a5668)
Diffstat (limited to 'Source/kwsys/Directory.cxx')
-rw-r--r-- | Source/kwsys/Directory.cxx | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/Source/kwsys/Directory.cxx b/Source/kwsys/Directory.cxx index 2e8aa83..6e31cbf 100644 --- a/Source/kwsys/Directory.cxx +++ b/Source/kwsys/Directory.cxx @@ -99,18 +99,21 @@ Status Directory::Load(std::string const& name, std::string* errorMessage) this->Clear(); intptr_t srchHandle; char* buf; + size_t bufLength; size_t n = name.size(); if (name.back() == '/' || name.back() == '\\') { - buf = new char[n + 1 + 1]; - sprintf(buf, "%s*", name.c_str()); + bufLength = n + 1 + 1; + buf = new char[bufLength]; + snprintf(buf, bufLength, "%s*", name.c_str()); } else { // Make sure the slashes in the wildcard suffix are consistent with the // rest of the path - buf = new char[n + 2 + 1]; + bufLength = n + 2 + 1; + buf = new char[bufLength]; if (name.find('\\') != std::string::npos) { - sprintf(buf, "%s\\*", name.c_str()); + snprintf(buf, bufLength, "%s\\*", name.c_str()); } else { - sprintf(buf, "%s/*", name.c_str()); + snprintf(buf, bufLength, "%s/*", name.c_str()); } } struct _wfinddata_t data; // data of current file @@ -148,13 +151,16 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name, { intptr_t srchHandle; char* buf; + size_t bufLength; size_t n = name.size(); if (name.back() == '/') { + bufLength = n + 1 + 1; buf = new char[n + 1 + 1]; - sprintf(buf, "%s*", name.c_str()); + snprintf(buf, bufLength, "%s*", name.c_str()); } else { + bufLength = n + 2 + 1; buf = new char[n + 2 + 1]; - sprintf(buf, "%s/*", name.c_str()); + snprintf(buf, bufLength, "%s/*", name.c_str()); } struct _wfinddata_t data; // data of current file |