summaryrefslogtreecommitdiffstats
path: root/Source/cmCommandArgumentParserHelper.cxx
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2020-02-26 14:52:47 (GMT)
committerMarc Chevrier <marc.chevrier@gmail.com>2020-02-27 10:11:30 (GMT)
commit557cecdc3d9ace51229b3dfce4a2ed71c2cc5c5c (patch)
tree656e2b8567e3c12c115bd1922f6bddb43c18a811 /Source/cmCommandArgumentParserHelper.cxx
parentab2d170c746d7cb68c39e9577cdaabc66668c0aa (diff)
downloadCMake-557cecdc3d9ace51229b3dfce4a2ed71c2cc5c5c.zip
CMake-557cecdc3d9ace51229b3dfce4a2ed71c2cc5c5c.tar.gz
CMake-557cecdc3d9ace51229b3dfce4a2ed71c2cc5c5c.tar.bz2
Modernize memory management
Update internals of various classes
Diffstat (limited to 'Source/cmCommandArgumentParserHelper.cxx')
-rw-r--r--Source/cmCommandArgumentParserHelper.cxx36
1 files changed, 18 insertions, 18 deletions
diff --git a/Source/cmCommandArgumentParserHelper.cxx b/Source/cmCommandArgumentParserHelper.cxx
index 613ae06..379836a 100644
--- a/Source/cmCommandArgumentParserHelper.cxx
+++ b/Source/cmCommandArgumentParserHelper.cxx
@@ -5,6 +5,9 @@
#include <cstring>
#include <iostream>
#include <sstream>
+#include <utility>
+
+#include <cm/memory>
#include "cmCommandArgumentLexer.h"
#include "cmMakefile.h"
@@ -40,10 +43,10 @@ const char* cmCommandArgumentParserHelper::AddString(const std::string& str)
if (str.empty()) {
return "";
}
- char* stVal = new char[str.size() + 1];
- strcpy(stVal, str.c_str());
- this->Variables.push_back(stVal);
- return stVal;
+ auto stVal = cm::make_unique<char[]>(str.size() + 1);
+ strcpy(stVal.get(), str.c_str());
+ this->Variables.push_back(std::move(stVal));
+ return this->Variables.back().get();
}
const char* cmCommandArgumentParserHelper::ExpandSpecialVariable(
@@ -136,11 +139,11 @@ const char* cmCommandArgumentParserHelper::CombineUnions(const char* in1,
return in1;
}
size_t len = strlen(in1) + strlen(in2) + 1;
- char* out = new char[len];
- strcpy(out, in1);
- strcat(out, in2);
- this->Variables.push_back(out);
- return out;
+ auto out = cm::make_unique<char[]>(len);
+ strcpy(out.get(), in1);
+ strcat(out.get(), in2);
+ this->Variables.push_back(std::move(out));
+ return this->Variables.back().get();
}
void cmCommandArgumentParserHelper::AllocateParserType(
@@ -153,11 +156,11 @@ void cmCommandArgumentParserHelper::AllocateParserType(
if (len == 0) {
return;
}
- char* out = new char[len + 1];
- memcpy(out, str, len);
- out[len] = 0;
- pt->str = out;
- this->Variables.push_back(out);
+ auto out = cm::make_unique<char[]>(len + 1);
+ memcpy(out.get(), str, len);
+ out.get()[len] = 0;
+ pt->str = out.get();
+ this->Variables.push_back(std::move(out));
}
bool cmCommandArgumentParserHelper::HandleEscapeSymbol(
@@ -235,10 +238,7 @@ int cmCommandArgumentParserHelper::ParseString(const char* str, int verb)
void cmCommandArgumentParserHelper::CleanupParser()
{
- for (char* var : this->Variables) {
- delete[] var;
- }
- this->Variables.erase(this->Variables.begin(), this->Variables.end());
+ this->Variables.clear();
}
int cmCommandArgumentParserHelper::LexInput(char* buf, int maxlen)