Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offset Coverity defects fixed #31

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/meta/src/TCling.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4784,8 +4784,8 @@ Long_t TCling::ClassInfo_GetBaseOffset(ClassInfo_t* derived, ClassInfo_t* target
if (TClinginfo->GetDecl() == TClinginfoTarget->GetDecl()) {
return 0;
}
TClingBaseClassInfo* binfo = new TClingBaseClassInfo(fInterpreter, TClinginfo, TClinginfoTarget);
return binfo->Offset(address);
TClingBaseClassInfo binfo(fInterpreter, TClinginfo, TClinginfoTarget);
return binfo.Offset(address);
}

//______________________________________________________________________________
Expand Down
45 changes: 29 additions & 16 deletions core/meta/src/TClingBaseClassInfo.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ static const string indent_string(" ");
TClingBaseClassInfo::TClingBaseClassInfo(cling::Interpreter* interp,
const TClingClassInfo* ci)
: fInterp(interp), fClassInfo(0), fFirstTime(true), fDescend(false),
fDecl(0), fIter(0), fBaseInfo(0), fOffset(0L)
fDecl(0), fIter(0), fBaseInfo(0), fOffset(0L), fClassInfoOwnership(false)
{
if (!ci) {
fClassInfo = new TClingClassInfo(interp);
fClassInfoOwnership = true;
return;
}
fClassInfo = ci;
Expand All @@ -87,7 +88,7 @@ TClingBaseClassInfo::TClingBaseClassInfo(cling::Interpreter* interp,
const TClingClassInfo* derived,
TClingClassInfo* base)
: fInterp(interp), fClassInfo(0), fFirstTime(true), fDescend(false),
fDecl(0), fIter(0), fBaseInfo(0), fOffset(0L)
fDecl(0), fIter(0), fBaseInfo(0), fOffset(0L), fClassInfoOwnership(false)
{
if (!derived->GetDecl()) {
return;
Expand Down Expand Up @@ -119,9 +120,9 @@ TClingBaseClassInfo::TClingBaseClassInfo(cling::Interpreter* interp,
TClingBaseClassInfo::TClingBaseClassInfo(const TClingBaseClassInfo& rhs)
: fInterp(rhs.fInterp), fClassInfo(0), fFirstTime(rhs.fFirstTime),
fDescend(rhs.fDescend), fDecl(rhs.fDecl), fIter(rhs.fIter), fBaseInfo(0),
fIterStack(rhs.fIterStack), fOffset(rhs.fOffset)
fIterStack(rhs.fIterStack), fOffset(rhs.fOffset), fClassInfoOwnership(false)
{
fClassInfo = new TClingClassInfo(*rhs.fClassInfo);
fClassInfo = rhs.fClassInfo;
fBaseInfo = new TClingClassInfo(*rhs.fBaseInfo);
}

Expand All @@ -140,6 +141,7 @@ TClingBaseClassInfo& TClingBaseClassInfo::operator=(
fBaseInfo = new TClingClassInfo(*rhs.fBaseInfo);
fIterStack = rhs.fIterStack;
fOffset = rhs.fOffset;
fClassInfoOwnership = true;
}
return *this;
}
Expand Down Expand Up @@ -220,12 +222,13 @@ OffsetPtrFunc_t TClingBaseClassInfo::GenerateBaseOffsetFunction(const TClingClas
for (cling::Transaction::const_iterator I = Tp->decls_begin(),
E = Tp->decls_end(); !WFD && I != E; ++I) {
if (I->m_Call == cling::Transaction::kCCIHandleTopLevelDecl) {
const FunctionDecl* createWFD = dyn_cast<FunctionDecl>(*I->m_DGR.begin());
if (createWFD && isa<TranslationUnitDecl>(createWFD->getDeclContext())) {
DeclarationName FName = createWFD->getDeclName();
if (const IdentifierInfo* FII = FName.getAsIdentifierInfo()) {
if (FII->getName() == wrapper_name) {
WFD = createWFD;
if (const FunctionDecl* createWFD = dyn_cast<FunctionDecl>(*I->m_DGR.begin())) {
if (createWFD && isa<TranslationUnitDecl>(createWFD->getDeclContext())) {
DeclarationName FName = createWFD->getDeclName();
if (const IdentifierInfo* FII = FName.getAsIdentifierInfo()) {
if (FII->getName() == wrapper_name) {
WFD = createWFD;
}
}
}
}
Expand Down Expand Up @@ -441,11 +444,12 @@ long TClingBaseClassInfo::Offset(void * address) const
if (!(Property() & kIsVirtualBase)) {
clang::ASTContext& Context = Base->getASTContext();
const clang::CXXRecordDecl* RD = llvm::dyn_cast<clang::CXXRecordDecl>(fDecl);
/*const clang::ASTRecordLayout& Layout = Context.getASTRecordLayout(RD);
int64_t offset = Layout.getBaseClassOffset(Base).getQuantity(); */
if (!RD) {
// No RecordDecl for the class.
return -1;
}
long clang_val = computeOffsetHint(Context, Base, RD).getQuantity();
if (clang_val == -2 || clang_val == -3) {
clang_val = -1;
TString baseName;
TString derivedName;
{
Expand Down Expand Up @@ -474,6 +478,7 @@ long TClingBaseClassInfo::Offset(void * address) const
"There are multiple paths from derived class %s to base class %s.",
derivedName.Data(), baseName.Data());
}
clang_val = -1;
}
return clang_val;
}
Expand All @@ -496,10 +501,20 @@ long TClingBaseClassInfo::Property() const
return 0L;
}
long property = 0L;

if (fDecl == fClassInfo->GetDecl()) {
property |= kIsDirectInherit;
}

const clang::CXXRecordDecl* CRD
= llvm::dyn_cast<CXXRecordDecl>(fDecl);
const clang::CXXRecordDecl* BaseCRD
= llvm::dyn_cast<CXXRecordDecl>(fBaseInfo->GetDecl());
if (!CRD || !BaseCRD) {
Error("TClingBaseClassInfo::Property"
, "The derived class and the base class do not have a CXXRecordDecl.");
return property;
}

clang::CXXBasePaths Paths(/*FindAmbiguities=*/false, /*RecordPaths=*/true,
/*DetectVirtual=*/true);
Expand All @@ -511,9 +526,7 @@ long TClingBaseClassInfo::Property() const
if (Paths.getDetectedVirtual()) {
property |= kIsVirtualBase;
}
if (fDecl == fClassInfo->GetDecl()) {
property |= kIsDirectInherit;
}

clang::AccessSpecifier AS = clang::AS_public;
// Derived: public Mid; Mid : protected Base: Derived inherits protected Base?
for (clang::CXXBasePaths::const_paths_iterator IB = Paths.begin(), EB = Paths.end();
Expand Down
1 change: 1 addition & 0 deletions core/meta/src/TClingBaseClassInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class TClingBaseClassInfo {
TClingClassInfo *fBaseInfo; // Base class our iterator is currently pointing at, we own.
std::vector<std::pair<std::pair<const clang::Decl*, clang::CXXRecordDecl::base_class_const_iterator>, long> > fIterStack; // Iterator stack.
long fOffset; // Offset of the current base, fDecl, in the most-derived class.
bool fClassInfoOwnership; // We created the fClassInfo and we need to delete it in the constructor.

public:

Expand Down