summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/Directory.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-10-27 15:21:46 (GMT)
committerBrad King <brad.king@kitware.com>2021-10-27 15:21:46 (GMT)
commit848eeba483bef0cfeeef78ae77dc3c9a7327b8ea (patch)
tree3f8066f2905e9c1deb97f3f48db165edf8017289 /Source/kwsys/Directory.cxx
parenta956be484783a991dbda3b14f676538d5f0b17bd (diff)
parent6015a898d463fc321187ae346155654d55393a4c (diff)
downloadCMake-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.cxx20
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