mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-22 06:59:01 -06:00
cmDependsJavaParserHelper: fix dangling pointer
The cmDependsJavaParserHelper tries to implement a "deep copy" in the assignment operator of the internal class CurrentClass. To do that, it uses std::copy and std::back_inserter. The copy constructor is implemented in terms of the assignment operator but it does not initialize the member NestedClasses, a pointer to vector. This pointer is dereferenced in the assignment operator. Change the pointer to a value and rely on the compiler generated special functions.
This commit is contained in:
committed by
Brad King
parent
f3d76a88b7
commit
fe27879c6b
@@ -48,7 +48,7 @@ public:
|
||||
|
||||
// For yacc
|
||||
void AddClassFound(const char* sclass);
|
||||
void PrepareElement(ParserType* opt);
|
||||
void PrepareElement(ParserType* me);
|
||||
void DeallocateParserType(char** pt);
|
||||
void CheckEmpty(int line, int cnt, ParserType* pt);
|
||||
void StartClass(const char* cls);
|
||||
@@ -69,20 +69,9 @@ private:
|
||||
{
|
||||
public:
|
||||
std::string Name;
|
||||
std::vector<CurrentClass>* NestedClasses;
|
||||
CurrentClass() { this->NestedClasses = new std::vector<CurrentClass>; }
|
||||
~CurrentClass() { delete this->NestedClasses; }
|
||||
CurrentClass& operator=(CurrentClass const& c)
|
||||
{
|
||||
this->NestedClasses->clear();
|
||||
this->Name = c.Name;
|
||||
std::copy(c.NestedClasses->begin(), c.NestedClasses->end(),
|
||||
std::back_inserter(*this->NestedClasses));
|
||||
return *this;
|
||||
}
|
||||
CurrentClass(CurrentClass const& c) { (*this) = c; }
|
||||
std::vector<CurrentClass> NestedClasses;
|
||||
void AddFileNamesForPrinting(std::vector<std::string>* files,
|
||||
const char* prefix, const char* sep);
|
||||
const char* prefix, const char* sep) const;
|
||||
};
|
||||
std::string CurrentPackage;
|
||||
std::string::size_type InputBufferPos;
|
||||
|
||||
Reference in New Issue
Block a user