summaryrefslogtreecommitdiffstats
path: root/Directory.cxx
diff options
context:
space:
mode:
authorKWSys Upstream <kwrobot@kitware.com>2021-10-27 13:30:56 (GMT)
committerBrad King <brad.king@kitware.com>2021-10-27 15:21:46 (GMT)
commit6015a898d463fc321187ae346155654d55393a4c (patch)
tree9413fdd221c42da73a35f6cf6c4945b67b13a18c /Directory.cxx
parent58f046ba26d67c6e1ceda2a20977e316f1a942ad (diff)
downloadCMake-6015a898d463fc321187ae346155654d55393a4c.zip
CMake-6015a898d463fc321187ae346155654d55393a4c.tar.gz
CMake-6015a898d463fc321187ae346155654d55393a4c.tar.bz2
KWSys 2021-10-27 (e19a5668)
Code extracted from: https://gitlab.kitware.com/utils/kwsys.git at commit e19a5668f01bb9d96440ce96e777749d6e92562d (e19a5668f01bb9d96440ce96e777749d6e92562d). Upstream Shortlog ----------------- Mathieu Westphal (1): e28d7282 DynamicLoader: Add RTLD_GLOBAL as a supported flag on linux Sean McBride (8): 704a63d4 Replace sprintf with snprintf f9f6d67b Replace non-standard _snprintf with standard snprintf f771c009 Fix -Wunused-macros warning by defining under same conditions as usage f3d4b12b Fix Wmissing-prototypes warnings by making functions static 6f4a1826 Fix Wmissing-variable-declarations by declaring variable in a header 31d25023 Fix all Wold-style-cast warnings 0f44b620 Fix Wreserved-id-macro warning by removing double underscore 44718539 Fix for extraneous semi-colon warning
Diffstat (limited to 'Directory.cxx')
-rw-r--r--Directory.cxx20
1 files changed, 13 insertions, 7 deletions
diff --git a/Directory.cxx b/Directory.cxx
index 2e8aa83..6e31cbf 100644
--- a/Directory.cxx
+++ b/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