From 8bd86fe60da2e0b6a2f77217a878d99f19e78512 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Wed, 15 Mar 2017 23:41:23 -0700 Subject: [PATCH] Address more cppcheck warnings, mostly around assignment operators & explicit constructors --- .gitignore | 1 + src/db/hierdatabase.cpp | 2 +- src/db/hierdatabase.h | 2 +- src/db/hierdbnode.h | 2 +- src/fco/fcocompare.h | 2 +- src/fco/fcodatasourceiterimpl.cpp | 2 +- src/fco/fconame.cpp | 10 +++++++--- src/fco/fconame.h | 10 +++++----- src/fco/fconametbl.h | 2 +- src/fco/fcopropvector.cpp | 6 ++---- src/fco/fcopropvector.h | 2 +- src/fco/fcosetimpl.cpp | 4 +++- src/fco/fcosetimpl.h | 11 ++++++----- src/fco/fcospecattr.h | 2 +- src/fco/fcospechelper.h | 2 +- src/fco/fcospecimpl.cpp | 4 +++- src/fco/fcospecimpl.h | 2 +- src/fco/fcospeclist.h | 4 ++-- src/fco/iterproxy.h | 1 + src/fs/fsobject.h | 2 +- src/tripwire/mailmessage.h | 2 +- src/tripwire/pipedmailmessage.cpp | 2 +- src/tw/configfile.h | 2 +- src/tw/dbdebug.h | 2 +- src/tw/fcodatabasefile.h | 4 ++-- src/tw/fcoreport.cpp | 12 +++++++++--- src/tw/fcoreport.h | 10 +++++----- src/tw/filemanipulator.h | 2 +- src/tw/textreportviewer.h | 4 +++- src/tw/twutil.cpp | 4 ++-- src/tw/twutil.h | 4 ++-- src/twcrypto/bytequeue.cpp | 2 +- src/twcrypto/bytequeue.h | 2 +- src/twcrypto/crypto.h | 28 ++++++++++++++-------------- src/twparser/parserobjects.h | 2 +- src/twparser/policyparser.h | 4 ++-- 36 files changed, 88 insertions(+), 71 deletions(-) diff --git a/.gitignore b/.gitignore index 4854d05..9e8c92b 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ src/tripwire/tripwire src/twadmin/twadmin src/twprint/twprint src/twtest/twtest +src/test-harness/twtest **/Makefile **/*.o **/*.dylib diff --git a/src/db/hierdatabase.cpp b/src/db/hierdatabase.cpp index 2a88614..b4fd831 100644 --- a/src/db/hierdatabase.cpp +++ b/src/db/hierdatabase.cpp @@ -751,7 +751,7 @@ bool cHierDatabaseIter::CompareForUpperBound( const cHierEntry& he, const TCHAR* class cHierDatabaseIterCallCompare { public: - cHierDatabaseIterCallCompare( const cHierDatabaseIter* pcls ) + explicit cHierDatabaseIterCallCompare( const cHierDatabaseIter* pcls ) : pc( pcls ) {}; bool operator()( const cHierEntry& a1, const TCHAR* a2 ) diff --git a/src/db/hierdatabase.h b/src/db/hierdatabase.h index 54d335f..1e3c173 100644 --- a/src/db/hierdatabase.h +++ b/src/db/hierdatabase.h @@ -114,7 +114,7 @@ private: class cHierDatabaseIter { public: - cHierDatabaseIter( cHierDatabase* pDb ); //throw (eArchive) + explicit cHierDatabaseIter( cHierDatabase* pDb ); //throw (eArchive) ~cHierDatabaseIter(); // diff --git a/src/db/hierdbnode.h b/src/db/hierdbnode.h index 560344e..148df88 100644 --- a/src/db/hierdbnode.h +++ b/src/db/hierdbnode.h @@ -68,7 +68,7 @@ public: }; - cHierNode( Type type = TYPE_INVALID ) : mType( type ) {} + explicit cHierNode( Type type = TYPE_INVALID ) : mType( type ) {} virtual ~cHierNode() {} int32 mType; diff --git a/src/fco/fcocompare.h b/src/fco/fcocompare.h index b7a6175..2343286 100644 --- a/src/fco/fcocompare.h +++ b/src/fco/fcocompare.h @@ -53,7 +53,7 @@ public: }; cFCOCompare(); - cFCOCompare( const cFCOPropVector& propsToCompare); + explicit cFCOCompare( const cFCOPropVector& propsToCompare); virtual ~cFCOCompare(); void SetPropsToCmp(const cFCOPropVector& pv); diff --git a/src/fco/fcodatasourceiterimpl.cpp b/src/fco/fcodatasourceiterimpl.cpp index 9f7cb88..c906188 100644 --- a/src/fco/fcodatasourceiterimpl.cpp +++ b/src/fco/fcodatasourceiterimpl.cpp @@ -440,7 +440,7 @@ bool cFCODataSourceIterImpl::CompareForUpperBound( const iFCO* pFCO, const TCHAR class cFCODataSourceIterImplCallCompare { public: - cFCODataSourceIterImplCallCompare( const cFCODataSourceIterImpl* pcls ) + explicit cFCODataSourceIterImplCallCompare( const cFCODataSourceIterImpl* pcls ) : pc( pcls ) {}; bool operator()( const iFCO* a1, const TCHAR* a2 ) diff --git a/src/fco/fconame.cpp b/src/fco/fconame.cpp index bc5ecaa..b3428d5 100644 --- a/src/fco/fconame.cpp +++ b/src/fco/fconame.cpp @@ -177,7 +177,7 @@ void cFCOName::SetNameInfo(iFCONameInfo* pNI) /////////////////////////////////////////////////////////////////////////////// // operator= /////////////////////////////////////////////////////////////////////////////// -void cFCOName::operator = (const cFCOName& rhs) +cFCOName& cFCOName::operator = (const cFCOName& rhs) { mpPathName->Release(); // TODO -- I am sure this won't work (const-ness) @@ -188,16 +188,19 @@ void cFCOName::operator = (const cFCOName& rhs) #ifdef _DEBUG mDebugStrName = AsString(); #endif + return *this; } -void cFCOName::operator = (const TSTRING& rhs) + +cFCOName& cFCOName::operator = (const TSTRING& rhs) { *this = rhs.c_str(); #ifdef _DEBUG mDebugStrName = AsString(); #endif + return *this; } -void cFCOName::operator = (const TCHAR* rhs) +cFCOName& cFCOName::operator = (const TCHAR* rhs) { // if I have the only handle on this vector, I can reuse it // otherwise, I have to release it. @@ -210,6 +213,7 @@ void cFCOName::operator = (const TCHAR* rhs) #ifdef _DEBUG mDebugStrName = AsString(); #endif + return *this; } void cFCOName::ParseString( const TCHAR* pszin ) diff --git a/src/fco/fconame.h b/src/fco/fconame.h index 0c6f05c..daccab0 100644 --- a/src/fco/fconame.h +++ b/src/fco/fconame.h @@ -58,7 +58,7 @@ class cFCOName : public iTypedSerializable public: typedef cFCONameIter iterator; - cFCOName(iFCONameInfo* iNI = NULL); + explicit cFCOName(iFCONameInfo* iNI = NULL); cFCOName(const cFCOName& rhs); explicit cFCOName(const TSTRING& rhs, iFCONameInfo* iNI = NULL); @@ -67,9 +67,9 @@ public: // do it unexpectedly virtual ~cFCOName(); - void operator = (const cFCOName& rhs); - void operator = (const TSTRING& rhs); - void operator = (const TCHAR* rhs); + cFCOName& operator = (const cFCOName& rhs); + cFCOName& operator = (const TSTRING& rhs); + cFCOName& operator = (const TCHAR* rhs); bool operator < (const cFCOName& rhs) const; // defines an arbitrary order for cFCONames. This is so that names can @@ -165,7 +165,7 @@ class cFCONameIter_i; class cFCONameIter { public: - cFCONameIter(const cFCOName& name); + explicit cFCONameIter(const cFCOName& name); ~cFCONameIter(); int GetSize() const; // returns the number of entries in the fco name diff --git a/src/fco/fconametbl.h b/src/fco/fconametbl.h index a1bbfff..16e2301 100644 --- a/src/fco/fconametbl.h +++ b/src/fco/fconametbl.h @@ -110,7 +110,7 @@ private: class cFCONameTbl { public: - cFCONameTbl(int defSize = HASH_VERY_LARGE); + explicit cFCONameTbl(int defSize = HASH_VERY_LARGE); // defSize is the initial hash table size ~cFCONameTbl(); diff --git a/src/fco/fcopropvector.cpp b/src/fco/fcopropvector.cpp index 449aaff..54c1bde 100644 --- a/src/fco/fcopropvector.cpp +++ b/src/fco/fcopropvector.cpp @@ -394,7 +394,6 @@ void cFCOPropVector::Read(iSerializer* pSerializer, int32 version) if (version > 0) ThrowAndAssert(eSerializerVersionMismatch(_T("Property Vector Read"))); - int i; int32 newSize; pSerializer->ReadInt32(newSize); ASSERT(newSize > 0); @@ -409,7 +408,7 @@ void cFCOPropVector::Read(iSerializer* pSerializer, int32 version) } else { - for (i=0; i <= mSize / msBitlength; ++i) + for (int i=0; i <= mSize / msBitlength; ++i) { int32 mask; pSerializer->ReadInt32(mask); @@ -421,7 +420,6 @@ void cFCOPropVector::Read(iSerializer* pSerializer, int32 version) void cFCOPropVector::Write(iSerializer* pSerializer) const { - int i; pSerializer->WriteInt32(mSize); if (mpBuf == NULL) @@ -430,7 +428,7 @@ void cFCOPropVector::Write(iSerializer* pSerializer) const } else { - for (i=0; i <= mSize / msBitlength; ++i) + for (int i=0; i <= mSize / msBitlength; ++i) pSerializer->WriteInt32((*mpBuf)[i]); } diff --git a/src/fco/fcopropvector.h b/src/fco/fcopropvector.h index 13378e4..7e2dc51 100644 --- a/src/fco/fcopropvector.h +++ b/src/fco/fcopropvector.h @@ -49,7 +49,7 @@ class cFCOPropVector : public iSerializable // note: this is not iTypedSerializable { public: - cFCOPropVector (int size = 32); + explicit cFCOPropVector (int size = 32); cFCOPropVector (const cFCOPropVector& rhs); virtual ~cFCOPropVector (void); bool operator== (const cFCOPropVector& rhs) const; diff --git a/src/fco/fcosetimpl.cpp b/src/fco/fcosetimpl.cpp index 2324ee0..a8f27d4 100644 --- a/src/fco/fcosetimpl.cpp +++ b/src/fco/fcosetimpl.cpp @@ -80,7 +80,7 @@ cFCOSetImpl::cFCOSetImpl(const cFCOSetImpl& rhs) : iFCOSet() /////////////////////////////////////////////////////////////////////////////// // operator= /////////////////////////////////////////////////////////////////////////////// -void cFCOSetImpl::operator=(const cFCOSetImpl& rhs) +cFCOSetImpl& cFCOSetImpl::operator=(const cFCOSetImpl& rhs) { std::set::const_iterator i; for(i = rhs.mFCOSet.begin(); i != rhs.mFCOSet.end(); ++i) @@ -88,6 +88,8 @@ void cFCOSetImpl::operator=(const cFCOSetImpl& rhs) i->mpFCO->AddRef(); mFCOSet.insert(cFCONode(i->mpFCO)); } + + return *this; } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/fco/fcosetimpl.h b/src/fco/fcosetimpl.h index 942ba8c..b7d3bef 100644 --- a/src/fco/fcosetimpl.h +++ b/src/fco/fcosetimpl.h @@ -56,7 +56,7 @@ public: cFCOSetImpl(); cFCOSetImpl(const cFCOSetImpl& rhs); virtual ~cFCOSetImpl(); - void operator=(const cFCOSetImpl& rhs); + cFCOSetImpl& operator=(const cFCOSetImpl& rhs); virtual const iFCOIter* Lookup(const cFCOName& name) const; virtual iFCOIter* Lookup(const cFCOName& name); @@ -85,8 +85,9 @@ private: const cFCOName* mpFCOName; cFCONode() : mpFCO(0), mpFCOName(0) {} - cFCONode(iFCO* pFCO) : mpFCO(pFCO), mpFCOName(&pFCO->GetName()) {} - cFCONode(const cFCOName& name) : mpFCO(0), mpFCOName(&name) {} + //TODO: make the iFCO* constructor explicit + cFCONode(iFCO* pFCO) : mpFCO(pFCO), mpFCOName(&pFCO->GetName()) {} + explicit cFCONode(const cFCOName& name) : mpFCO(0), mpFCOName(&name) {} cFCONode(const cFCONode& rhs) : mpFCO(rhs.mpFCO), mpFCOName(rhs.mpFCOName) {} bool operator < (const cFCONode& rhs) const { if(mpFCOName) return (*mpFCOName < *rhs.mpFCOName); else return false; } bool operator ==(const cFCONode& rhs) const { if(mpFCOName) return (*mpFCOName == *rhs.mpFCOName); else return false; } @@ -101,8 +102,8 @@ class cFCOIterImpl : public iFCOIter friend class cFCOSetImpl; public: - cFCOIterImpl(cFCOSetImpl* pSet); - cFCOIterImpl(const cFCOSetImpl* pSet); + explicit cFCOIterImpl(cFCOSetImpl* pSet); + explicit cFCOIterImpl(const cFCOSetImpl* pSet); virtual void SeekBegin() const; virtual bool Done() const; diff --git a/src/fco/fcospecattr.h b/src/fco/fcospecattr.h index 9e0cba7..b369758 100644 --- a/src/fco/fcospecattr.h +++ b/src/fco/fcospecattr.h @@ -94,7 +94,7 @@ private: class cFCOSpecAttrEmailIter { public: - cFCOSpecAttrEmailIter(const cFCOSpecAttr& attr); + explicit cFCOSpecAttrEmailIter(const cFCOSpecAttr& attr); ~cFCOSpecAttrEmailIter(); void SeekBegin() const; diff --git a/src/fco/fcospechelper.h b/src/fco/fcospechelper.h index c9f13e8..af4ef29 100644 --- a/src/fco/fcospechelper.h +++ b/src/fco/fcospechelper.h @@ -159,7 +159,7 @@ protected: class cFCOSpecStopPointIter { public: - cFCOSpecStopPointIter(cFCOSpecStopPointSet& set); + explicit cFCOSpecStopPointIter(cFCOSpecStopPointSet& set); void SeekBegin() const; // seeks to the beginning of the stop point list diff --git a/src/fco/fcospecimpl.cpp b/src/fco/fcospecimpl.cpp index 2e664e7..839e282 100644 --- a/src/fco/fcospecimpl.cpp +++ b/src/fco/fcospecimpl.cpp @@ -100,11 +100,13 @@ IMPLEMENT_SERREFCOUNT(cFCOSpecImpl, _T("cFCOSpecImpl"), 0, 1); /////////////////////////////////////////////////////////////////////////////// // operator= /////////////////////////////////////////////////////////////////////////////// -void cFCOSpecImpl::operator=(const cFCOSpecImpl& rhs) +cFCOSpecImpl& cFCOSpecImpl::operator=(const cFCOSpecImpl& rhs) { mName = rhs.mName; mPropVector = rhs.mPropVector; mpHelper = rhs.mpHelper ? rhs.mpHelper->Clone() : 0; + + return *this; } /////////////////////////////////////////////////////////////////////////////// // Clone -- make a copy of this spec diff --git a/src/fco/fcospecimpl.h b/src/fco/fcospecimpl.h index 17cd308..0bfa028 100644 --- a/src/fco/fcospecimpl.h +++ b/src/fco/fcospecimpl.h @@ -70,7 +70,7 @@ public: // the spec will delete whatever helper it contains when it is destroyed cFCOSpecImpl(const cFCOSpecImpl& rhs); cFCOSpecImpl(); - void operator=(const cFCOSpecImpl& rhs); + cFCOSpecImpl& operator=(const cFCOSpecImpl& rhs); // from iFCOSpec virtual bool SpecContainsFCO (const cFCOName& name) const; diff --git a/src/fco/fcospeclist.h b/src/fco/fcospeclist.h index a7beff2..d149c13 100644 --- a/src/fco/fcospeclist.h +++ b/src/fco/fcospeclist.h @@ -103,7 +103,7 @@ protected: class cFCOSpecListAddedIter { public: - cFCOSpecListAddedIter(const cFCOSpecList& list); + explicit cFCOSpecListAddedIter(const cFCOSpecList& list); ~cFCOSpecListAddedIter(); void SeekBegin() const; @@ -129,7 +129,7 @@ protected: class cFCOSpecListCanonicalIter { public: - cFCOSpecListCanonicalIter(const cFCOSpecList& list); + explicit cFCOSpecListCanonicalIter(const cFCOSpecList& list); ~cFCOSpecListCanonicalIter(); void SeekBegin() const; diff --git a/src/fco/iterproxy.h b/src/fco/iterproxy.h index 7743392..21fdfca 100644 --- a/src/fco/iterproxy.h +++ b/src/fco/iterproxy.h @@ -50,6 +50,7 @@ template class cIterProxy { public: + //TODO: Can these 2 constructors be made explicit? cIterProxy(TYPE* pIter = NULL) : mpIter(pIter) {}; cIterProxy(const TYPE* pIter) : mpIter((TYPE*)pIter) {}; ~cIterProxy() { if (mpIter) mpIter->DestroyIter(); } diff --git a/src/fs/fsobject.h b/src/fs/fsobject.h index eb3a09e..9121137 100644 --- a/src/fs/fsobject.h +++ b/src/fs/fsobject.h @@ -60,7 +60,7 @@ class cFSObject : public iFCO DECLARE_SERREFCOUNT() public: - cFSObject(const cFCOName& name); + explicit cFSObject(const cFCOName& name); virtual void SetName(const cFCOName& name) ; virtual const cFCOName& GetName() const ; diff --git a/src/tripwire/mailmessage.h b/src/tripwire/mailmessage.h index dfec57c..19b0617 100644 --- a/src/tripwire/mailmessage.h +++ b/src/tripwire/mailmessage.h @@ -255,7 +255,7 @@ private: class cPipedMailMessage : public cMailMessage { public: - cPipedMailMessage(TSTRING strSendMailExePath); + explicit cPipedMailMessage(const TSTRING& strSendMailExePath); virtual ~cPipedMailMessage(); virtual bool Send(); //throw(eMailMessageError) diff --git a/src/tripwire/pipedmailmessage.cpp b/src/tripwire/pipedmailmessage.cpp index 15cd432..ea81f9f 100644 --- a/src/tripwire/pipedmailmessage.cpp +++ b/src/tripwire/pipedmailmessage.cpp @@ -49,7 +49,7 @@ // // Constructor. Not much to do beside initialize the handle to the DLL // -cPipedMailMessage::cPipedMailMessage(TSTRING strSendMailExePath) +cPipedMailMessage::cPipedMailMessage(const TSTRING& strSendMailExePath) { mstrSendMailExePath = strSendMailExePath; mpFile = NULL; diff --git a/src/tw/configfile.h b/src/tw/configfile.h index b7100a4..2546a97 100644 --- a/src/tw/configfile.h +++ b/src/tw/configfile.h @@ -140,7 +140,7 @@ private: class cConfigFileIter { public: - cConfigFileIter( cConfigFile& cf); + explicit cConfigFileIter( cConfigFile& cf); virtual ~cConfigFileIter(); void SeekBegin() const; diff --git a/src/tw/dbdebug.h b/src/tw/dbdebug.h index 857630d..d90a0b6 100644 --- a/src/tw/dbdebug.h +++ b/src/tw/dbdebug.h @@ -98,7 +98,7 @@ public: // Ctor, Dtor: ~cDebugHierDbIter () {} - cDebugHierDbIter ( cHierDatabase* pDb ) : cHierDatabaseIter( pDb ) {} + explicit cDebugHierDbIter ( cHierDatabase* pDb ) : cHierDatabaseIter( pDb ) {} // // Methods for obtaining protected members of cHierDatabaseIter: diff --git a/src/tw/fcodatabasefile.h b/src/tw/fcodatabasefile.h index 907596d..875ed4b 100644 --- a/src/tw/fcodatabasefile.h +++ b/src/tw/fcodatabasefile.h @@ -112,7 +112,7 @@ public: //------------------------------------------------------------------------- struct tEntry { - tEntry( cGenre::Genre genre ); + explicit tEntry( cGenre::Genre genre ); // the ctor will get the appropriate database construction parameters // based on the genre number. ~tEntry( ) @@ -146,7 +146,7 @@ private: class cFCODatabaseFileIter { public: - cFCODatabaseFileIter( cFCODatabaseFile& dbFile ); + explicit cFCODatabaseFileIter( cFCODatabaseFile& dbFile ); void SeekBegin(); void Next(); diff --git a/src/tw/fcoreport.cpp b/src/tw/fcoreport.cpp index 79af470..4bc800d 100644 --- a/src/tw/fcoreport.cpp +++ b/src/tw/fcoreport.cpp @@ -239,10 +239,12 @@ cFCOReportGenreIter::~cFCOReportGenreIter() delete mpData; } -void cFCOReportGenreIter::operator=(const cFCOReportGenreIter& rhs) +cFCOReportGenreIter& cFCOReportGenreIter::operator=(const cFCOReportGenreIter& rhs) { mpData->mpList = rhs.mpData->mpList; mpData->mIter = rhs.mpData->mIter; + + return *this; } // iteration methods @@ -380,13 +382,15 @@ cFCOReportSpecIter::cFCOReportSpecIter(const cFCOReportSpecIter& rhs) *this = rhs; } -void cFCOReportSpecIter::operator=(const cFCOReportSpecIter& rhs) +cFCOReportSpecIter& cFCOReportSpecIter::operator=(const cFCOReportSpecIter& rhs) { if (mpData == 0) mpData = new cFCOReportSpecIter_i(); mpData->mpList = rhs.mpData->mpList; mpData->mIter = rhs.mpData->mIter; + + return *this; } int cFCOReportSpecIter::GetNumChanged() const @@ -525,10 +529,12 @@ cFCOReportChangeIter::~cFCOReportChangeIter() delete mpData; } -void cFCOReportChangeIter::operator=(const cFCOReportChangeIter& rhs) +cFCOReportChangeIter& cFCOReportChangeIter::operator=(const cFCOReportChangeIter& rhs) { mpData->mpList = rhs.mpData->mpList; mpData->mIter = rhs.mpData->mIter; + + return *this; } void cFCOReportChangeIter::SetSpecIter(const cFCOReportSpecIter& specIter) diff --git a/src/tw/fcoreport.h b/src/tw/fcoreport.h index 7da27d1..7010edf 100644 --- a/src/tw/fcoreport.h +++ b/src/tw/fcoreport.h @@ -147,7 +147,7 @@ public: cFCOReportGenreIter(const cFCOReportGenreIter& rhs); ~cFCOReportGenreIter(); - void operator=(const cFCOReportGenreIter& rhs); + cFCOReportGenreIter& operator=(const cFCOReportGenreIter& rhs); // iteration methods void SeekBegin() const; @@ -179,13 +179,13 @@ public: cFCOReportSpecIter(cFCOReport& report, cGenre::Genre genre); // if genre does not exist in the report, it will be added to the report with // and empty spec list. - cFCOReportSpecIter(const cFCOReportGenreIter& genreIter); + explicit cFCOReportSpecIter(const cFCOReportGenreIter& genreIter); // thorws eInternal if genreIter is not at a valid genre or is Done() cFCOReportSpecIter(const cFCOReportSpecIter& rhs); ~cFCOReportSpecIter(); - void operator=(const cFCOReportSpecIter& rhs); + cFCOReportSpecIter& operator=(const cFCOReportSpecIter& rhs); // iteration methods void SeekBegin() const; @@ -226,11 +226,11 @@ private: class cFCOReportChangeIter { public: - cFCOReportChangeIter(const cFCOReportSpecIter& specIter); + explicit cFCOReportChangeIter(const cFCOReportSpecIter& specIter); cFCOReportChangeIter(const cFCOReportChangeIter& rhs); ~cFCOReportChangeIter(); - void operator=(const cFCOReportChangeIter& rhs); + cFCOReportChangeIter& operator=(const cFCOReportChangeIter& rhs); void SetSpecIter(const cFCOReportSpecIter& specIter); // assocaite this iterator with a different spec. We will assert // that specIter.Done() is not true. diff --git a/src/tw/filemanipulator.h b/src/tw/filemanipulator.h index 59f53a9..bb5c893 100644 --- a/src/tw/filemanipulator.h +++ b/src/tw/filemanipulator.h @@ -91,7 +91,7 @@ TSS_FILE_EXCEPTION( eFileManipUnrecognizedFileType, eFileManip ) class cFileManipulator { public: - cFileManipulator(const TCHAR* filename); + explicit cFileManipulator(const TCHAR* filename); // throws eArchive if file does not exist cFileManipulator(const cFileManipulator& rhs); ~cFileManipulator(); diff --git a/src/tw/textreportviewer.h b/src/tw/textreportviewer.h index 6a2762d..32ad6a1 100644 --- a/src/tw/textreportviewer.h +++ b/src/tw/textreportviewer.h @@ -155,7 +155,7 @@ protected: RuleSummaryLine() : mSeverity(0), mAddedObjects(0), mRemovedObjects(0), mChangedObjects(0) {} RuleSummaryLine(const RuleSummaryLine& rhs) { *this = rhs; } - void operator = (const RuleSummaryLine& rhs) + RuleSummaryLine& operator = (const RuleSummaryLine& rhs) { mSpecName = rhs.mSpecName; mSeverity = rhs.mSeverity; @@ -163,6 +163,8 @@ protected: mRemovedObjects = rhs.mRemovedObjects; mChangedObjects = rhs.mChangedObjects; mStartPoint = rhs.mStartPoint; + + return *this; } }; diff --git a/src/tw/twutil.cpp b/src/tw/twutil.cpp index 46b9ab8..956d4d5 100644 --- a/src/tw/twutil.cpp +++ b/src/tw/twutil.cpp @@ -855,7 +855,7 @@ void cTWUtil::ReadConfigText(cArchive &arch, TSTRING& configText, cArchive* pBag // of the policy file text to disk. // Will throw eError on failure. -void cTWUtil::WritePolicyText(const TCHAR* filename, const std::string polText, bool bEncrypt, const cElGamalSigPrivateKey* pPrivateKey) +void cTWUtil::WritePolicyText(const TCHAR* filename, const std::string& polText, bool bEncrypt, const cElGamalSigPrivateKey* pPrivateKey) { cSerializableNString nstring; @@ -874,7 +874,7 @@ void cTWUtil::WritePolicyText(const TCHAR* filename, const std::string polText, cDisplayEncoder::EncodeInline( filename ).c_str() ); } -void cTWUtil::WritePolicyText(cArchive &archive, const std::string polText, bool bEncrypt, const cElGamalSigPrivateKey* pPrivateKey) +void cTWUtil::WritePolicyText(cArchive &archive, const std::string& polText, bool bEncrypt, const cElGamalSigPrivateKey* pPrivateKey) { cSerializableNString nstring; diff --git a/src/tw/twutil.h b/src/tw/twutil.h index 451f834..9c51978 100644 --- a/src/tw/twutil.h +++ b/src/tw/twutil.h @@ -122,8 +122,8 @@ public: // eSerializer is thrown if reading or writing fails // eConfigFile is thrown if config file does not parse correctly during reading - static void WritePolicyText(const TCHAR* filename, const std::string policyText, bool bEncrypt, const cElGamalSigPrivateKey* pPrivateKey); - static void WritePolicyText(cArchive &archive, const std::string policyText, bool bEncrypt, const cElGamalSigPrivateKey* pPrivateKey); + static void WritePolicyText(const TCHAR* filename, const std::string& policyText, bool bEncrypt, const cElGamalSigPrivateKey* pPrivateKey); + static void WritePolicyText(cArchive &archive, const std::string& policyText, bool bEncrypt, const cElGamalSigPrivateKey* pPrivateKey); static void ReadPolicyText(const TCHAR* filename, std::string& policyText, const cElGamalSigPublicKey* pPublicKey); static void ReadPolicyText(cArchive &archive, std::string& policyText, const cElGamalSigPublicKey* pPublicKey); // read and write policy file to and from disk diff --git a/src/twcrypto/bytequeue.cpp b/src/twcrypto/bytequeue.cpp index 9d7ade5..118f464 100644 --- a/src/twcrypto/bytequeue.cpp +++ b/src/twcrypto/bytequeue.cpp @@ -46,7 +46,7 @@ class cByteQueueNode { public: - cByteQueueNode(unsigned int maxSize); + explicit cByteQueueNode(unsigned int maxSize); unsigned int CurrentSize() const {return tail-head;} diff --git a/src/twcrypto/bytequeue.h b/src/twcrypto/bytequeue.h index e64484e..9d1511f 100644 --- a/src/twcrypto/bytequeue.h +++ b/src/twcrypto/bytequeue.h @@ -45,7 +45,7 @@ class cByteQueueNode; class cByteQueue : public BufferedTransformation { public: - cByteQueue(int nodeSize=1024); + explicit cByteQueue(int nodeSize=1024); cByteQueue(const cByteQueue ©); ~cByteQueue(); diff --git a/src/twcrypto/crypto.h b/src/twcrypto/crypto.h index 6dd5d08..ddd5d13 100644 --- a/src/twcrypto/crypto.h +++ b/src/twcrypto/crypto.h @@ -147,9 +147,9 @@ public: KEY2048 = 2048 }; - cRSA(KeySize keysize); - cRSA(const cRSAPublicKey& publicKey); // read keysize from key - cRSA(const cRSAPrivateKey& privateKey); // ditto + explicit cRSA(KeySize keysize); + explicit cRSA(const cRSAPublicKey& publicKey); // read keysize from key + explicit cRSA(const cRSAPrivateKey& privateKey); // ditto virtual ~cRSA(); void SetEncrypting(const cRSAPublicKey* pKey); @@ -183,7 +183,7 @@ class cRSAPrivateKey friend class cRSA; friend class cRSAPublicKey; public: - cRSAPrivateKey(void* pDataStream); + explicit cRSAPrivateKey(void* pDataStream); ~cRSAPrivateKey(); int GetWriteLen() const; @@ -202,8 +202,8 @@ class cRSAPublicKey { friend class cRSA; public: - cRSAPublicKey(void* pDataStream); - cRSAPublicKey(const cRSAPrivateKey& privateKey); + explicit cRSAPublicKey(void* pDataStream); + explicit cRSAPublicKey(const cRSAPrivateKey& privateKey); ~cRSAPublicKey(); int GetWriteLen() const; @@ -249,9 +249,9 @@ public: KEY2048 = 2048 }; - cElGamalSig(KeySize keysize); - cElGamalSig(const cElGamalSigPublicKey& publicKey); // read keysize from key - cElGamalSig(const cElGamalSigPrivateKey& privateKey); // ditto + explicit cElGamalSig(KeySize keysize); + explicit cElGamalSig(const cElGamalSigPublicKey& publicKey); // read keysize from key + explicit cElGamalSig(const cElGamalSigPrivateKey& privateKey); // ditto virtual ~cElGamalSig(); void SetSigning(const cElGamalSigPrivateKey* pKey); @@ -285,7 +285,7 @@ class cElGamalSigPrivateKey friend class cElGamalSig; friend class cElGamalSigPublicKey; public: - cElGamalSigPrivateKey(void* pDataStream); + explicit cElGamalSigPrivateKey(void* pDataStream); ~cElGamalSigPrivateKey(); int GetWriteLen() const; @@ -304,8 +304,8 @@ class cElGamalSigPublicKey { friend class cElGamalSig; public: - cElGamalSigPublicKey(void* pDataStream); - cElGamalSigPublicKey(const cElGamalSigPrivateKey& privateKey); + explicit cElGamalSigPublicKey(void* pDataStream); + explicit cElGamalSigPublicKey(const cElGamalSigPrivateKey& privateKey); ~cElGamalSigPublicKey(); int GetWriteLen() const; @@ -332,7 +332,7 @@ private: class cHashedKey128 { public: - cHashedKey128(const TSTRING& data); + explicit cHashedKey128(const TSTRING& data); cHashedKey128(void* pData, int dataLen); ~cHashedKey128(); @@ -368,7 +368,7 @@ inline void cHashedKey128::Write(void* pDataStream) class cHashedKey192 { public: - cHashedKey192(const TSTRING& data); + explicit cHashedKey192(const TSTRING& data); cHashedKey192(void* pData, int dataLen); ~cHashedKey192(); diff --git a/src/twparser/parserobjects.h b/src/twparser/parserobjects.h index 969beb3..3100be9 100644 --- a/src/twparser/parserobjects.h +++ b/src/twparser/parserobjects.h @@ -238,7 +238,7 @@ public: // // ctors and dtor // - cParseRule( const cParseSpecMask& defSpecMask ) :mDefSpecMask( defSpecMask ), mpAttrList(0), mpSpecMaskList(0), mName(_T("")) {} + explicit cParseRule( const cParseSpecMask& defSpecMask ) :mDefSpecMask( defSpecMask ), mpAttrList(0), mpSpecMaskList(0), mName(_T("")) {} ~cParseRule(); // diff --git a/src/twparser/policyparser.h b/src/twparser/policyparser.h index 9ef6de0..85139d1 100644 --- a/src/twparser/policyparser.h +++ b/src/twparser/policyparser.h @@ -76,7 +76,7 @@ class tw_yy_scan : public yy_scan { enum { MAX_TOKEN_LENGTH = 1024 }; public: - tw_yy_scan( std::istream& i ) : yy_scan( MAX_TOKEN_LENGTH ), mIn(i) {}; // need to increase token length over mks default + explicit tw_yy_scan( std::istream& i ) : yy_scan( MAX_TOKEN_LENGTH ), mIn(i) {}; // need to increase token length over mks default virtual int yygetc() { return mIn.get(); }; @@ -123,7 +123,7 @@ private: class cPolicyParser { public: - cPolicyParser( std::istream& in ); // input source + explicit cPolicyParser( std::istream& in ); // input source void Execute( cGenreSpecListVector& policy, cErrorBucket* pError ); //throw(eError); void Check( cErrorBucket* pError ); //throw(eError);