From d3f859bfbd256322a258c9c5eb58638758bf831e Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Wed, 15 Mar 2017 00:47:52 -0700 Subject: [PATCH] Address some cppcheck warnings around initializers & catching by reference --- src/fco/fcodatasourceiterimpl.cpp | 2 +- src/fco/genreswitcher.cpp | 6 ++---- src/tripwire/tripwiremain.cpp | 4 ++-- src/tripwire/twcmdline.cpp | 2 +- src/tripwire/twcmdline.h | 7 +++++-- src/tw/filemanipulator.cpp | 3 ++- src/tw/textreportviewer.cpp | 4 +++- src/tw/textreportviewer.h | 2 +- src/twadmin/twadminmain.cpp | 4 ++-- src/twprint/twprintmain.cpp | 4 ++-- 10 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/fco/fcodatasourceiterimpl.cpp b/src/fco/fcodatasourceiterimpl.cpp index a21fa80..709c881 100644 --- a/src/fco/fcodatasourceiterimpl.cpp +++ b/src/fco/fcodatasourceiterimpl.cpp @@ -52,7 +52,7 @@ //========================================================================= cFCODataSourceIterImpl::cFCODataSourceIterImpl() - : mFlags(0) + : mpErrorBucket(0), mFlags(0) { } diff --git a/src/fco/genreswitcher.cpp b/src/fco/genreswitcher.cpp index d1e5796..e3bee5e 100644 --- a/src/fco/genreswitcher.cpp +++ b/src/fco/genreswitcher.cpp @@ -99,14 +99,12 @@ cGenre::Genre cGenreSwitcher::GetDefaultGenre() void cGenreSwitcher::RegisterGenre( const cGenreInfo* pGI, RegisterFlags flags /* = REGISTER_FLAGS_NONE */ ) { cDebug d("cGenreSwitcher::RegisterGenre"); - d.TraceDebug( _T("ID: %x, long name: %s, short name: %s\n"), pGI->m_ID, pGI->m_sLongName.c_str(), pGI->m_sShortName.c_str() ); - // - // validate params - // ASSERT( NULL != pGI ); ASSERT( pGI->IsValid() ); + d.TraceDebug( _T("ID: %x, long name: %s, short name: %s\n"), pGI->m_ID, pGI->m_sLongName.c_str(), pGI->m_sShortName.c_str() ); + // // can only be one of each genre ID // diff --git a/src/tripwire/tripwiremain.cpp b/src/tripwire/tripwiremain.cpp index f93d4f1..a94d6c5 100644 --- a/src/tripwire/tripwiremain.cpp +++ b/src/tripwire/tripwiremain.cpp @@ -243,7 +243,7 @@ int __cdecl _tmain( int argc, const TCHAR* argv[ ], const TCHAR* envp[ ] ) ret = 8; } - catch (std::bad_alloc e) + catch (std::bad_alloc& e) { // Note: We use fputs rather than TCERR as it will probably require the // least amount of memory to do its thing. If we ran out of memory we @@ -253,7 +253,7 @@ int __cdecl _tmain( int argc, const TCHAR* argv[ ], const TCHAR* envp[ ] ) ret = 8; } - catch (std::exception e) + catch (std::exception& e) { TCERR << _T("*** Fatal exception: "); std::cerr << e.what() << std::endl; diff --git a/src/tripwire/twcmdline.cpp b/src/tripwire/twcmdline.cpp index 8a59a7f..dcd22d0 100644 --- a/src/tripwire/twcmdline.cpp +++ b/src/tripwire/twcmdline.cpp @@ -1476,7 +1476,7 @@ public: cFCOReportHeader* mpReportHeader; // ctor can set up some default values - cTWModeDbUpdate_i() : cTWModeCommon(), mbInteractive(true), mbSecureMode(true), /*mSiteProvided(false),*/ mpReport(0), mpDbFile(0), mpReportHeader(0) {} + cTWModeDbUpdate_i() : cTWModeCommon(), mbInteractive(true), mbSecureMode(true), mbEncryptDb(true), /*mSiteProvided(false),*/ mpReport(0), mpDbFile(0), mpReportHeader(0) {} }; /////////////////////////////////////////////////////////////////////////////// diff --git a/src/tripwire/twcmdline.h b/src/tripwire/twcmdline.h index 59e8141..1dd1c45 100644 --- a/src/tripwire/twcmdline.h +++ b/src/tripwire/twcmdline.h @@ -182,14 +182,17 @@ class cTWModeCommon bool mMailNoViolations; // Email out reports with no violations? TSTRING mMailFrom; - cTWModeCommon() : mVerbosity(1), + cTWModeCommon() : mVerbosity(1), mLocalProvided(false), mbLatePassphrase(false), mfLooseDirs(false), mbResetAccessTime(false), mbLogToSyslog(false), mbCrossFileSystems(false), - mbDirectIO(false) + mbDirectIO(false), + mMailMethod(cMailMessage::NO_METHOD), + mSmtpPort(25), + mMailNoViolations(true) { } }; diff --git a/src/tw/filemanipulator.cpp b/src/tw/filemanipulator.cpp index 4ab1283..0ee37c3 100644 --- a/src/tw/filemanipulator.cpp +++ b/src/tw/filemanipulator.cpp @@ -61,7 +61,8 @@ cFileManipulator::cFileManipulator(const TCHAR* filename) } cFileManipulator::cFileManipulator(const cFileManipulator& rhs) -: mFileName(rhs.mFileName), +: mbInit(false), + mFileName(rhs.mFileName), mFileHeader(rhs.mFileHeader) { } diff --git a/src/tw/textreportviewer.cpp b/src/tw/textreportviewer.cpp index bbbf5ea..f29a6f0 100644 --- a/src/tw/textreportviewer.cpp +++ b/src/tw/textreportviewer.cpp @@ -143,7 +143,8 @@ int cTextReportViewer::Init( const cFCOReportHeader& h, cFCOReport& r ) { mpHeader = &h; mpReport = &r; - mpOut = NULL; + mpOut = NULL; + mpIn = NULL; mpCurPD = NULL; mpCurNT = NULL; mfUpdate = false; @@ -152,6 +153,7 @@ int cTextReportViewer::Init( const cFCOReportHeader& h, cFCOReport& r ) mErrorNum = 1; mReportingLevel = FULL_REPORT; mfGotNumbers = false; + mCurrentChar[0] = '\0'; mCurrentCharSize = 0; return 0; } diff --git a/src/tw/textreportviewer.h b/src/tw/textreportviewer.h index b5321f6..6a2762d 100644 --- a/src/tw/textreportviewer.h +++ b/src/tw/textreportviewer.h @@ -153,7 +153,7 @@ protected: int mChangedObjects; TSTRING mStartPoint; - RuleSummaryLine() {} + RuleSummaryLine() : mSeverity(0), mAddedObjects(0), mRemovedObjects(0), mChangedObjects(0) {} RuleSummaryLine(const RuleSummaryLine& rhs) { *this = rhs; } void operator = (const RuleSummaryLine& rhs) { diff --git a/src/twadmin/twadminmain.cpp b/src/twadmin/twadminmain.cpp index 500cef5..718ea82 100644 --- a/src/twadmin/twadminmain.cpp +++ b/src/twadmin/twadminmain.cpp @@ -203,14 +203,14 @@ int __cdecl _tmain( int argc, const TCHAR* argv[ ], const TCHAR* envp[ ] ) ret = 1; } - catch (std::bad_alloc e) + catch (std::bad_alloc& e) { TCERR << _T("*** Fatal exception: Out of memory "); TCERR << _T("*** Exiting...\n"); ret = 1; } - catch (std::exception e) + catch (std::exception& e) { TCERR << _T("*** Fatal exception: "); std::cerr << e.what() << std::endl; diff --git a/src/twprint/twprintmain.cpp b/src/twprint/twprintmain.cpp index 474b109..85fbe2a 100644 --- a/src/twprint/twprintmain.cpp +++ b/src/twprint/twprintmain.cpp @@ -217,14 +217,14 @@ int __cdecl _tmain( int argc, const TCHAR* argv[ ] ) ret = 1; } - catch (std::bad_alloc e) + catch (std::bad_alloc& e) { TCERR << _T("*** Fatal exception: Out of memory "); TCERR << _T("*** Exiting...\n"); ret = 1; } - catch (std::exception e) + catch (std::exception& e) { TCERR << _T("*** Fatal exception: "); std::cerr << e.what() << std::endl;