diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2020-03-02 09:41:17 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-03-05 12:34:01 (GMT) |
commit | 9de0355d4f8f56a71f3d18b1b2c3d50dc8624aae (patch) | |
tree | ec6050654d073ec970e81fe51d95cf0110d02efd /Source/cmProcessOutput.cxx | |
parent | 07a7bc0e3fc370eaa5593cffcd07c0ea739cfc9c (diff) | |
download | CMake-9de0355d4f8f56a71f3d18b1b2c3d50dc8624aae.zip CMake-9de0355d4f8f56a71f3d18b1b2c3d50dc8624aae.tar.gz CMake-9de0355d4f8f56a71f3d18b1b2c3d50dc8624aae.tar.bz2 |
Modernize memory management
Update internals of various classes.
Diffstat (limited to 'Source/cmProcessOutput.cxx')
-rw-r--r-- | Source/cmProcessOutput.cxx | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/Source/cmProcessOutput.cxx b/Source/cmProcessOutput.cxx index e80ea5c..0fb4ff7 100644 --- a/Source/cmProcessOutput.cxx +++ b/Source/cmProcessOutput.cxx @@ -4,7 +4,10 @@ #include "cmProcessOutput.h" #if defined(_WIN32) +# include <cm/memory> + # include <windows.h> + unsigned int cmProcessOutput::defaultCodepage = KWSYS_ENCODING_DEFAULT_CODEPAGE; #endif @@ -143,9 +146,9 @@ bool cmProcessOutput::DoDecodeText(std::string raw, std::string& decoded, bool success = false; const int wlength = MultiByteToWideChar(codepage, 0, raw.c_str(), int(raw.size()), NULL, 0); - wchar_t* wdata = new wchar_t[wlength]; - int r = MultiByteToWideChar(codepage, 0, raw.c_str(), int(raw.size()), wdata, - wlength); + auto wdata = cm::make_unique<wchar_t[]>(wlength); + int r = MultiByteToWideChar(codepage, 0, raw.c_str(), int(raw.size()), + wdata.get(), wlength); if (r > 0) { if (lastChar) { *lastChar = 0; @@ -154,18 +157,16 @@ bool cmProcessOutput::DoDecodeText(std::string raw, std::string& decoded, *lastChar = wdata[wlength - 1]; } } - int length = WideCharToMultiByte(defaultCodepage, 0, wdata, wlength, NULL, - 0, NULL, NULL); - char* data = new char[length]; - r = WideCharToMultiByte(defaultCodepage, 0, wdata, wlength, data, length, - NULL, NULL); + int length = WideCharToMultiByte(defaultCodepage, 0, wdata.get(), wlength, + NULL, 0, NULL, NULL); + auto data = cm::make_unique<char[]>(length); + r = WideCharToMultiByte(defaultCodepage, 0, wdata.get(), wlength, + data.get(), length, NULL, NULL); if (r > 0) { - decoded = std::string(data, length); + decoded = std::string(data.get(), length); success = true; } - delete[] data; } - delete[] wdata; return success; } #endif |