diff --git a/Source/kwsys/ProcessWin32.c b/Source/kwsys/ProcessWin32.c index 0b43b4a2af..c1a566f4ad 100644 --- a/Source/kwsys/ProcessWin32.c +++ b/Source/kwsys/ProcessWin32.c @@ -666,14 +666,14 @@ int kwsysProcess_SetWorkingDirectory(kwsysProcess* cp, const char* dir) if (dir && dir[0]) { wchar_t* wdir = kwsysEncoding_DupToWide(dir); /* We must convert the working directory to a full path. */ - DWORD length = GetFullPathNameW(wdir, 0, 0, 0); + DWORD length = GetFullPathNameW(wdir, 0, NULL, NULL); if (length > 0) { wchar_t* work_dir = malloc(length * sizeof(wchar_t)); if (!work_dir) { free(wdir); return 0; } - if (!GetFullPathNameW(wdir, length, work_dir, 0)) { + if (!GetFullPathNameW(wdir, length, work_dir, NULL)) { free(work_dir); free(wdir); return 0; diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index cb6d73b7c8..f690476824 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -59,9 +59,6 @@ #include #include -#ifdef __QNX__ -# include /* for malloc/free on QNX */ -#endif #include #include #include @@ -338,10 +335,9 @@ inline void Realpath(const std::string& path, std::string& resolved_path, std::string* errorMessage = nullptr) { std::wstring tmp = KWSYS_NAMESPACE::Encoding::ToWide(path); - wchar_t* ptemp; wchar_t fullpath[MAX_PATH]; DWORD bufferLen = GetFullPathNameW( - tmp.c_str(), sizeof(fullpath) / sizeof(fullpath[0]), fullpath, &ptemp); + tmp.c_str(), sizeof(fullpath) / sizeof(fullpath[0]), fullpath, nullptr); if (bufferLen < sizeof(fullpath) / sizeof(fullpath[0])) { resolved_path = KWSYS_NAMESPACE::Encoding::ToNarrow(fullpath); KWSYS_NAMESPACE::SystemTools::ConvertToUnixSlashes(resolved_path); @@ -824,25 +820,14 @@ static int kwsysUnPutEnv(const std::string& env) #elif defined(__CYGWIN__) || defined(__GLIBC__) /* putenv("A") removes A from the environment. It must not put the memory in the environment because it does not have any "=" syntax. */ + static int kwsysUnPutEnv(const std::string& env) { int err = 0; - size_t pos = env.find('='); - size_t const len = pos == std::string::npos ? env.size() : pos; - size_t const sz = len + 1; - char local_buf[256]; - char* buf = sz > sizeof(local_buf) ? (char*)malloc(sz) : local_buf; - if (!buf) { - return -1; - } - strncpy(buf, env.c_str(), len); - buf[len] = 0; - if (putenv(buf) < 0 && errno != EINVAL) { + std::string buf = env.substr(0, env.find('=')); + if (putenv(&buf[0]) < 0 && errno != EINVAL) { err = errno; } - if (buf != local_buf) { - free(buf); - } if (err) { errno = err; return -1;