Kaydet (Commit) 4d89865e authored tarafından Noel Grandin's avatar Noel Grandin

new loplugin:deadclass

look for classes which only have copy/move constructors, and so are
effectively dead

Change-Id: I0b844f301e2200c2b40031856bfdb0b0e2c8f77d
Reviewed-on: https://gerrit.libreoffice.org/41039Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 84fc4dec
......@@ -624,62 +624,6 @@ SbxInfo::SbxInfo( const OUString& r, sal_uInt32 n )
: aHelpFile( r ), nHelpId( n )
{}
// SbxAlias
SbxAlias::SbxAlias( const SbxAlias& r )
: SvRefBase( r ), SbxVariable( r ),
SfxListener( r ), xAlias( r.xAlias )
{}
SbxAlias& SbxAlias::operator=( const SbxAlias& r )
{
xAlias = r.xAlias;
return *this;
}
SbxAlias::~SbxAlias()
{
if( xAlias.is() )
{
EndListening( xAlias->GetBroadcaster() );
}
}
void SbxAlias::Broadcast( SfxHintId nHt )
{
if( xAlias.is() )
{
xAlias->SetParameters( GetParameters() );
if( nHt == SfxHintId::BasicDataWanted )
{
SbxVariable::operator=( *xAlias );
}
else if( nHt == SfxHintId::BasicDataChanged || nHt == SfxHintId::BasicConverted )
{
*xAlias = *this;
}
else if( nHt == SfxHintId::BasicInfoWanted )
{
xAlias->Broadcast( nHt );
pInfo = xAlias->GetInfo();
}
}
}
void SbxAlias::Notify( SfxBroadcaster&, const SfxHint& rHint )
{
const SbxHint* p = dynamic_cast<const SbxHint*>(&rHint);
if( p && p->GetId() == SfxHintId::BasicDying )
{
xAlias.clear();
// delete the alias?
if( pParent )
{
pParent->Remove( this );
}
}
}
void SbxVariable::Dump( SvStream& rStrm, bool bFill )
{
OString aBNameStr(OUStringToOString(GetName( SbxNameType::ShortTypes ), RTL_TEXTENCODING_ASCII_US));
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "plugin.hxx"
namespace {
class DeadClass:
public RecursiveASTVisitor<DeadClass>, public loplugin::Plugin
{
public:
explicit DeadClass(InstantiationData const & data): Plugin(data) {}
void run() override;
bool VisitCXXRecordDecl(CXXRecordDecl const *);
};
void DeadClass::run() {
if (compiler.getLangOpts().CPlusPlus) {
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
}
}
bool DeadClass::VisitCXXRecordDecl(CXXRecordDecl const * decl) {
if (ignoreLocation(decl) || !decl->isThisDeclarationADefinition())
return true;
if (decl->needsImplicitDefaultConstructor())
return true;
if (decl->getDescribedClassTemplate())
return true;
if (isa<ClassTemplateSpecializationDecl>(decl))
return true;
int otherCnt = 0;
int copyMoveCnt = 0;
for (auto i = decl->ctor_begin(); i != decl->ctor_end(); ++i) {
if (!i->isUserProvided())
continue;
// if (i->getTemplatedKind() != clang::FunctionDecl::TK_NonTemplate)
// return true;
// if (i->getTemplateInstantiationPattern())
// return true;
if (i->isCopyOrMoveConstructor())
copyMoveCnt++;
else
otherCnt++;
}
if (otherCnt == 0 && copyMoveCnt > 0)
{
report(
DiagnosticsEngine::Warning,
"class has only copy/move constructors, must be dead",
decl->getLocStart())
<< decl->getSourceRange();
for (auto i = decl->ctor_begin(); i != decl->ctor_end(); ++i) {
if (i->isDeleted())
continue;
i->dump();
}
}
return true;
}
loplugin::Plugin::Registration<DeadClass> X("deadclass");
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
struct Foo { // expected-error {{class has only copy/move constructors, must be dead [loplugin:deadclass]}}
Foo(Foo&);
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
......@@ -97,18 +97,6 @@ public:
SbxVariable* GetVar() const { return pVar; }
};
// SbxAlias is an alias for a var or object
class BASIC_DLLPUBLIC SbxAlias : public SbxVariable, public SfxListener
{
SbxVariableRef xAlias;
virtual ~SbxAlias() override;
virtual void Broadcast( SfxHintId ) override;
virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
public:
SbxAlias( const SbxAlias& );
SbxAlias& operator=( const SbxAlias& );
};
// SbxArray is an unidimensional, dynamic Array
// The variables convert from SbxVariablen. Put()/Insert() into the
// declared datatype, if they are not SbxVARIANT.
......
......@@ -54,43 +54,6 @@ private:
bool mbValid; /// True = decoder is correctly initialized.
};
/** Decodes BIFF stream contents that are encoded using the old XOR algorithm. */
class BiffDecoder_XOR : public BiffDecoderBase
{
private:
/** Copy constructor for cloning. */
BiffDecoder_XOR( const BiffDecoder_XOR& rDecoder );
/** Implements password verification and initialization of the decoder. */
virtual css::uno::Sequence< css::beans::NamedValue > implVerifyPassword( const OUString& rPassword ) override;
virtual bool implVerifyEncryptionData( const css::uno::Sequence< css::beans::NamedValue >& rEncryptionData ) override;
private:
::oox::core::BinaryCodec_XOR maCodec; /// Cipher algorithm implementation.
css::uno::Sequence< css::beans::NamedValue > maEncryptionData;
sal_uInt16 mnKey;
sal_uInt16 mnHash;
};
/** Decodes BIFF stream contents that are encoded using the RC4 algorithm. */
class BiffDecoder_RCF : public BiffDecoderBase
{
private:
/** Copy constructor for cloning. */
BiffDecoder_RCF( const BiffDecoder_RCF& rDecoder );
/** Implements password verification and initialization of the decoder. */
virtual css::uno::Sequence< css::beans::NamedValue > implVerifyPassword( const OUString& rPassword ) override;
virtual bool implVerifyEncryptionData( const css::uno::Sequence< css::beans::NamedValue >& rEncryptionData ) override;
private:
::oox::core::BinaryCodec_RCF maCodec; /// Cipher algorithm implementation.
css::uno::Sequence< css::beans::NamedValue > maEncryptionData;
::std::vector< sal_uInt8 > maSalt;
::std::vector< sal_uInt8 > maVerifier;
::std::vector< sal_uInt8 > maVerifierHash;
};
} // namespace xls
} // namespace oox
......
......@@ -52,105 +52,6 @@ BiffDecoderBase::~BiffDecoderBase()
return mbValid ? ::comphelper::DocPasswordVerifierResult::OK : ::comphelper::DocPasswordVerifierResult::WrongPassword;
}
BiffDecoder_XOR::BiffDecoder_XOR( const BiffDecoder_XOR& rDecoder ) :
BiffDecoderBase(), // must be called to prevent compiler warning
maCodec(),
maEncryptionData( rDecoder.maEncryptionData ),
mnKey( rDecoder.mnKey ),
mnHash( rDecoder.mnHash )
{
if( isValid() )
maCodec.initCodec( maEncryptionData );
}
Sequence< NamedValue > BiffDecoder_XOR::implVerifyPassword( const OUString& rPassword )
{
maEncryptionData.realloc( 0 );
/* Convert password to a byte string. TODO: this needs some finetuning
according to the spec... */
OString aBytePassword = OUStringToOString( rPassword, osl_getThreadTextEncoding() );
sal_Int32 nLen = aBytePassword.getLength();
if( (0 < nLen) && (nLen < 16) )
{
// init codec
maCodec.initKey( reinterpret_cast< const sal_uInt8* >( aBytePassword.getStr() ) );
if( maCodec.verifyKey( mnKey, mnHash ) )
maEncryptionData = maCodec.getEncryptionData();
}
return maEncryptionData;
}
bool BiffDecoder_XOR::implVerifyEncryptionData( const Sequence< NamedValue >& rEncryptionData )
{
maEncryptionData.realloc( 0 );
if( rEncryptionData.hasElements() )
{
// init codec
maCodec.initCodec( rEncryptionData );
if( maCodec.verifyKey( mnKey, mnHash ) )
maEncryptionData = rEncryptionData;
}
return maEncryptionData.hasElements();
}
BiffDecoder_RCF::BiffDecoder_RCF( const BiffDecoder_RCF& rDecoder ) :
BiffDecoderBase(), // must be called to prevent compiler warning
maEncryptionData( rDecoder.maEncryptionData ),
maSalt( rDecoder.maSalt ),
maVerifier( rDecoder.maVerifier ),
maVerifierHash( rDecoder.maVerifierHash )
{
if( isValid() )
maCodec.initCodec( maEncryptionData );
}
Sequence< NamedValue > BiffDecoder_RCF::implVerifyPassword( const OUString& rPassword )
{
maEncryptionData.realloc( 0 );
sal_Int32 nLen = rPassword.getLength();
if( (0 < nLen) && (nLen < 16) )
{
// copy string to sal_uInt16 array
::std::vector< sal_uInt16 > aPassVect( 16 );
const sal_Unicode* pcChar = rPassword.getStr();
const sal_Unicode* pcCharEnd = pcChar + nLen;
::std::vector< sal_uInt16 >::iterator aIt = aPassVect.begin();
for( ; pcChar < pcCharEnd; ++pcChar, ++aIt )
*aIt = static_cast< sal_uInt16 >( *pcChar );
// init codec
maCodec.initKey(aPassVect.data(), maSalt.data());
if (maCodec.verifyKey(maVerifier.data(), maVerifierHash.data()))
maEncryptionData = maCodec.getEncryptionData();
}
return maEncryptionData;
}
bool BiffDecoder_RCF::implVerifyEncryptionData( const Sequence< NamedValue >& rEncryptionData )
{
maEncryptionData.realloc( 0 );
if( rEncryptionData.hasElements() )
{
// init codec
maCodec.initCodec( rEncryptionData );
if (maCodec.verifyKey(maVerifier.data(), maVerifierHash.data()))
maEncryptionData = rEncryptionData;
}
return maEncryptionData.hasElements();
}
} // namespace xls
} // namespace oox
......
......@@ -13,6 +13,7 @@ $(eval $(call gb_CompilerTest_add_exception_objects,compilerplugins_clang, \
compilerplugins/clang/test/casttovoid \
compilerplugins/clang/test/constparams \
compilerplugins/clang/test/cppunitassertequals \
compilerplugins/clang/test/deadclass \
compilerplugins/clang/test/datamembershadow \
compilerplugins/clang/test/externvar \
compilerplugins/clang/test/finalprotected \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment