[Cmake-commits] CMake branch, next, updated. v3.6.0-rc2-354-g7f71c4e
Daniel Pfeifer
daniel at pfeifer-mail.de
Thu Jun 16 18:03:06 EDT 2016
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".
The branch, next has been updated
via 7f71c4e28b43f1eaa78a0227f97eac653eabebe0 (commit)
via a48f911ac7ec28e5301314482ae7f317d15fc3d8 (commit)
from 6493db09edb969b292538b4011bd9075d956063d (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7f71c4e28b43f1eaa78a0227f97eac653eabebe0
commit 7f71c4e28b43f1eaa78a0227f97eac653eabebe0
Merge: 6493db0 a48f911
Author: Daniel Pfeifer <daniel at pfeifer-mail.de>
AuthorDate: Thu Jun 16 18:03:05 2016 -0400
Commit: CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Thu Jun 16 18:03:05 2016 -0400
Merge topic 'cmDependsJavaParserHelper-dangling-ptr' into next
a48f911a cmDependsJavaParserHelper: fix dangling pointer
https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=a48f911ac7ec28e5301314482ae7f317d15fc3d8
commit a48f911ac7ec28e5301314482ae7f317d15fc3d8
Author: Daniel Pfeifer <daniel at pfeifer-mail.de>
AuthorDate: Thu Jun 16 23:51:36 2016 +0200
Commit: Daniel Pfeifer <daniel at pfeifer-mail.de>
CommitDate: Fri Jun 17 00:02:17 2016 +0200
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, so include-what-you-use requests
<algorithm> and <iterator>. 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 removes the need to include <algorithm> and <iterator>
in the header.
diff --git a/Source/cmDependsJavaParserHelper.cxx b/Source/cmDependsJavaParserHelper.cxx
index bd3ee4d..52072d4 100644
--- a/Source/cmDependsJavaParserHelper.cxx
+++ b/Source/cmDependsJavaParserHelper.cxx
@@ -13,7 +13,12 @@
#include "cmDependsJavaLexer.h"
#include "cmSystemTools.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <cmsys/FStream.hxx>
+#include <iostream>
int cmDependsJava_yyparse(yyscan_t yyscanner);
@@ -35,7 +40,7 @@ cmDependsJavaParserHelper::~cmDependsJavaParserHelper()
}
void cmDependsJavaParserHelper::CurrentClass::AddFileNamesForPrinting(
- std::vector<std::string>* files, const char* prefix, const char* sep)
+ std::vector<std::string>* files, const char* prefix, const char* sep) const
{
std::string rname = "";
if (prefix) {
@@ -44,8 +49,8 @@ void cmDependsJavaParserHelper::CurrentClass::AddFileNamesForPrinting(
}
rname += this->Name;
files->push_back(rname);
- std::vector<CurrentClass>::iterator it;
- for (it = this->NestedClasses->begin(); it != this->NestedClasses->end();
+ std::vector<CurrentClass>::const_iterator it;
+ for (it = this->NestedClasses.begin(); it != this->NestedClasses.end();
++it) {
it->AddFileNamesForPrinting(files, rname.c_str(), sep);
}
@@ -191,25 +196,19 @@ void cmDependsJavaParserHelper::StartClass(const char* cls)
void cmDependsJavaParserHelper::EndClass()
{
- CurrentClass* parent = 0;
- CurrentClass* current = 0;
- if (!this->ClassStack.empty()) {
- current = &(*(this->ClassStack.end() - 1));
- if (this->ClassStack.size() > 1) {
- parent = &(*(this->ClassStack.end() - 2));
- }
- }
- if (current == 0) {
+ if (this->ClassStack.empty()) {
std::cerr << "Error when parsing. Current class is null" << std::endl;
abort();
}
- if (parent == 0) {
+ if (this->ClassStack.size() <= 1) {
std::cerr << "Error when parsing. Parent class is null" << std::endl;
abort();
}
+ CurrentClass& current = this->ClassStack.back();
+ CurrentClass& parent = this->ClassStack[this->ClassStack.size() - 2];
this->CurrentDepth--;
- parent->NestedClasses->push_back(*current);
- this->ClassStack.erase(this->ClassStack.end() - 1, this->ClassStack.end());
+ parent.NestedClasses.push_back(current);
+ this->ClassStack.pop_back();
}
void cmDependsJavaParserHelper::PrintClasses()
@@ -228,10 +227,10 @@ void cmDependsJavaParserHelper::PrintClasses()
std::vector<std::string> cmDependsJavaParserHelper::GetFilesProduced()
{
std::vector<std::string> files;
- CurrentClass* toplevel = &(*(this->ClassStack.begin()));
- std::vector<CurrentClass>::iterator it;
- for (it = toplevel->NestedClasses->begin();
- it != toplevel->NestedClasses->end(); ++it) {
+ CurrentClass const& toplevel = this->ClassStack.front();
+ std::vector<CurrentClass>::const_iterator it;
+ for (it = toplevel.NestedClasses.begin(); it != toplevel.NestedClasses.end();
+ ++it) {
it->AddFileNamesForPrinting(&files, 0, "$");
}
return files;
@@ -309,11 +308,10 @@ int cmDependsJavaParserHelper::LexInput(char* buf, int maxlen)
if (buf[0] == '\n') {
this->CurrentLine++;
}
- return (1);
- } else {
- buf[0] = '\n';
- return (0);
+ return 1;
}
+ buf[0] = '\n';
+ return 0;
}
void cmDependsJavaParserHelper::Error(const char* str)
{
diff --git a/Source/cmDependsJavaParserHelper.h b/Source/cmDependsJavaParserHelper.h
index a13d023..731bbcc 100644
--- a/Source/cmDependsJavaParserHelper.h
+++ b/Source/cmDependsJavaParserHelper.h
@@ -12,7 +12,10 @@
#ifndef cmDependsJavaParserHelper_h
#define cmDependsJavaParserHelper_h
-#include "cmStandardIncludes.h"
+#include <cmConfigure.h> // IWYU pragma: keep
+
+#include <string>
+#include <vector>
#define YYSTYPE cmDependsJavaParserHelper::ParserType
#define YYSTYPE_IS_DECLARED
@@ -48,7 +51,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 +72,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;
-----------------------------------------------------------------------
Summary of changes:
Source/cmDependsJavaParserHelper.cxx | 44 ++++++++++++++++------------------
Source/cmDependsJavaParserHelper.h | 22 ++++++-----------
2 files changed, 28 insertions(+), 38 deletions(-)
hooks/post-receive
--
CMake
More information about the Cmake-commits
mailing list