Fix various Clang static analyzer quibbles

This commit is contained in:
Brian Cox 2017-02-20 23:21:00 -08:00
parent 86baf94ddf
commit d6df22f9dc
11 changed files with 68 additions and 65 deletions

View File

@ -1323,7 +1323,9 @@ cWcharIs32BitUcs2Converterer::Convert(
throw eConverterFatal( TSS_GetString( cCore, core::STR_ERR_ISNULL ) ); throw eConverterFatal( TSS_GetString( cCore, core::STR_ERR_ISNULL ) );
// cast our dbchar_t to wchar_t's first // cast our dbchar_t to wchar_t's first
ntwcs_t pwzBuffer = new wchar_t[ nCount + 1 ]; std::vector<wchar_t> buf(nCount+1);
wchar_t* pwzBuffer = &buf[0];
for( size_t n = 0; n < nCount; n++ ) for( size_t n = 0; n < nCount; n++ )
pwzBuffer[n] = pwz[n]; pwzBuffer[n] = pwz[n];
pwzBuffer[nCount] = 0x00; // null terminate pwzBuffer[nCount] = 0x00; // null terminate
@ -1358,7 +1360,8 @@ cWcharIs32BitUcs2Converterer::Convert(
throw eConverterFatal( TSS_GetString( cCore, core::STR_ERR_ISNULL ) ); throw eConverterFatal( TSS_GetString( cCore, core::STR_ERR_ISNULL ) );
// mb to wc to a buffer of wide chars then.... // mb to wc to a buffer of wide chars then....
wchar_t* pwzBuffer = new wchar_t[ nCount ]; std::vector<wchar_t> buf(nCount);
wchar_t* pwzBuffer = &buf[0];
int nConv = tss_mbstowcs( pwzBuffer, pbz, nCount ); int nConv = tss_mbstowcs( pwzBuffer, pbz, nCount );
if ( nConv == -1 ) if ( nConv == -1 )
@ -1451,6 +1454,9 @@ cGoodEnoughConverterer::Convert(
throw eConverterFatal( TSS_GetString( cCore, core::STR_ERR_ISNULL ) ); throw eConverterFatal( TSS_GetString( cCore, core::STR_ERR_ISNULL ) );
char* at = pbz; char* at = pbz;
if (pwz)
{
const dbchar_t* dat = pwz; const dbchar_t* dat = pwz;
while ( *dat ) while ( *dat )
{ {
@ -1466,6 +1472,7 @@ cGoodEnoughConverterer::Convert(
at++; at++;
dat++; dat++;
} }
}
*at = 0x00; *at = 0x00;
@ -1481,8 +1488,11 @@ cGoodEnoughConverterer::Convert(
if ( pwz == 0 || ( pbz == 0 && nBytes ) ) if ( pwz == 0 || ( pbz == 0 && nBytes ) )
throw eConverterFatal( TSS_GetString( cCore, core::STR_ERR_ISNULL ) ); throw eConverterFatal( TSS_GetString( cCore, core::STR_ERR_ISNULL ) );
const char* at = pbz;
dbchar_t* dat = pwz; dbchar_t* dat = pwz;
if (pbz)
{
const char* at = pbz;
while ( *at ) while ( *at )
{ {
if( (unsigned char)*at > (unsigned char)0x7Fu ) if( (unsigned char)*at > (unsigned char)0x7Fu )
@ -1497,7 +1507,7 @@ cGoodEnoughConverterer::Convert(
dat++; dat++;
at++; at++;
} }
}
*dat = 0x0000; *dat = 0x0000;
return( ( (size_t)dat - (size_t)pwz ) / sizeof( dbchar_t ) ); return( ( (size_t)dat - (size_t)pwz ) / sizeof( dbchar_t ) );

View File

@ -1105,8 +1105,8 @@ bool util_GetNextPathElement( const TSTRING& strPathC, TSTRING& strElem, int ind
TSTRING strPath = strPathC; // writable local version TSTRING strPath = strPathC; // writable local version
bool fMoreSeps = true; bool fMoreSeps = true;
TSTRING::size_type firstSep, nextSep, nextNonSep; TSTRING::size_type nextSep, nextNonSep;
firstSep = nextSep = nextNonSep = (TSTRING::size_type)-1; nextSep = nextNonSep = (TSTRING::size_type)-1;
for( int i = 0; i <= index && fMoreSeps; i++ ) for( int i = 0; i <= index && fMoreSeps; i++ )
{ {
// go past leading separators // go past leading separators

View File

@ -259,9 +259,13 @@ int cFCOPropVector::SetSize(int max)
return mSize = ((*mpBuf).capacity() * msBitlength); return mSize = ((*mpBuf).capacity() * msBitlength);
} }
else //mpBuf!=NULL && max>msBitlength else //mpBuf!=NULL && max>msBitlength
{
if (mpBuf)
{ {
(*mpBuf).resize (((max/msBitlength)+1), 0); (*mpBuf).resize (((max/msBitlength)+1), 0);
return mSize = ((*mpBuf).capacity() * msBitlength); mSize = ((*mpBuf).capacity() * msBitlength);
}
return mSize;
} }
} }

View File

@ -353,6 +353,8 @@ void cIntegrityCheck::ProcessDir( cDbDataSourceIter dbIter, iFCODataSourceIter*
if( dbIter.Done() ) if( dbIter.Done() )
{ {
ASSERT( pIter != 0); ASSERT( pIter != 0);
if (pIter)
{
d.TraceDetail( "Examining <done> and %s\n", pIter->GetName().AsString().c_str() ); d.TraceDetail( "Examining <done> and %s\n", pIter->GetName().AsString().c_str() );
// //
// these are all new entries, add them to the "Added" set... // these are all new entries, add them to the "Added" set...
@ -360,6 +362,7 @@ void cIntegrityCheck::ProcessDir( cDbDataSourceIter dbIter, iFCODataSourceIter*
ProcessAddedFCO( dbIter, pIter ); ProcessAddedFCO( dbIter, pIter );
pIter->Next(); pIter->Next();
} }
}
else if( ! pIter ) else if( ! pIter )
{ {
ASSERT( ! dbIter.Done() ); ASSERT( ! dbIter.Done() );

View File

@ -273,10 +273,6 @@ private:
void SendInit();// throw (eMailMessageError) void SendInit();// throw (eMailMessageError)
// opens a pipe to sendmail and writes the header. // opens a pipe to sendmail and writes the header.
FILE* GetFilePointer() const;
// returns a pointer to the current file pointer. Only valid between
// SendInit() and SendFinit()
void SendFinit(); //throw (eMailMessageError) void SendFinit(); //throw (eMailMessageError)
// closes the file descriptor, sending the rest of the message // closes the file descriptor, sending the rest of the message

View File

@ -80,8 +80,7 @@ bool cPipedMailMessage::Send()
SendInit(); SendInit();
FILE* sendPipe = GetFilePointer(); ASSERT( mpFile != 0 );
ASSERT( sendPipe != 0 );
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Get Body and Attachments // Get Body and Attachments
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -213,8 +212,3 @@ void cPipedMailMessage::SendFinit() //throw ( eMailMessageError )
} }
FILE* cPipedMailMessage::GetFilePointer() const
{
return mpFile;
}

View File

@ -450,6 +450,7 @@ void cDbDebug::OutputResults( void )
// Begin code for manipulating Database -- This is just a straight port from the DbExplore code. It's presence is // Begin code for manipulating Database -- This is just a straight port from the DbExplore code. It's presence is
// purely for convenience, and for debugging this class. // purely for convenience, and for debugging this class.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
static inline bool IsSpace( TCHAR c ) static inline bool IsSpace( TCHAR c )
{ {
return ( (c == _T(' ')) || (c == _T('\t')) || (c == _T('\r')) || (c == _T('\n')) || (c == _T('\0')) ); return ( (c == _T(' ')) || (c == _T('\t')) || (c == _T('\r')) || (c == _T('\n')) || (c == _T('\0')) );
@ -460,7 +461,6 @@ static inline bool IsEnd( TCHAR c )
return ( (c == _T('\0')) ); return ( (c == _T('\0')) );
} }
/*
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// util_PrintFCO // util_PrintFCO
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -514,13 +514,6 @@ cFCOReportChangeIter::cFCOReportChangeIter(const cFCOReportSpecIter& specIter)
SetSpecIter(specIter); SetSpecIter(specIter);
} }
cFCOReportChangeIter::cFCOReportChangeIter()
{
mpData = new cFCOReportChangeIter_i;
mpData->mpList = 0;
mpData->mIter = mpData->mpList->begin();
}
cFCOReportChangeIter::cFCOReportChangeIter(const cFCOReportChangeIter& rhs) cFCOReportChangeIter::cFCOReportChangeIter(const cFCOReportChangeIter& rhs)
{ {
mpData = new cFCOReportChangeIter_i; mpData = new cFCOReportChangeIter_i;

View File

@ -227,7 +227,6 @@ class cFCOReportChangeIter
{ {
public: public:
cFCOReportChangeIter(const cFCOReportSpecIter& specIter); cFCOReportChangeIter(const cFCOReportSpecIter& specIter);
cFCOReportChangeIter();
cFCOReportChangeIter(const cFCOReportChangeIter& rhs); cFCOReportChangeIter(const cFCOReportChangeIter& rhs);
~cFCOReportChangeIter(); ~cFCOReportChangeIter();
@ -251,6 +250,8 @@ public:
const cFCOPropVector& GetChangeVector() const; const cFCOPropVector& GetChangeVector() const;
private: private:
cFCOReportChangeIter() {}
cFCOReportChangeIter_i* mpData; cFCOReportChangeIter_i* mpData;
// TODO -- if it turns out that we are creating a lot of these, we should consider // TODO -- if it turns out that we are creating a lot of these, we should consider
// making a pool of them. // making a pool of them.

View File

@ -1519,6 +1519,9 @@ void cTextReportViewer::DisplayChangedProps( const iFCO* const pfcoOld, const iF
void cTextReportViewer::OutputAddedSummary( const cFCOReportSpecIter& ri, FCOList* pFCONameList ) void cTextReportViewer::OutputAddedSummary( const cFCOReportSpecIter& ri, FCOList* pFCONameList )
{ {
if (!pFCONameList)
return;
if( ! ri.GetAddedSet()->IsEmpty() ) if( ! ri.GetAddedSet()->IsEmpty() )
{ {
(*mpOut) << TSS_GetString( cTW, tw::STR_ADDED ) << _T(":") << endl; (*mpOut) << TSS_GetString( cTW, tw::STR_ADDED ) << _T(":") << endl;
@ -1539,6 +1542,9 @@ void cTextReportViewer::OutputAddedSummary( const cFCOReportSpecIter& ri, FCOLis
void cTextReportViewer::OutputRemovedSummary( const cFCOReportSpecIter& ri, FCOList* pFCONameList) void cTextReportViewer::OutputRemovedSummary( const cFCOReportSpecIter& ri, FCOList* pFCONameList)
{ {
if (!pFCONameList)
return;
if( ! ri.GetRemovedSet()->IsEmpty() ) if( ! ri.GetRemovedSet()->IsEmpty() )
{ {
(*mpOut) << TSS_GetString( cTW, tw::STR_REMOVED ) << _T(":") << endl; (*mpOut) << TSS_GetString( cTW, tw::STR_REMOVED ) << _T(":") << endl;
@ -1559,6 +1565,9 @@ void cTextReportViewer::OutputRemovedSummary( const cFCOReportSpecIter& ri, FCOL
void cTextReportViewer::OutputChangedSummary( const cFCOReportSpecIter& ri, FCOList* pFCONameList ) void cTextReportViewer::OutputChangedSummary( const cFCOReportSpecIter& ri, FCOList* pFCONameList )
{ {
if (!pFCONameList)
return;
if( ri.GetNumChanged() > 0 ) if( ri.GetNumChanged() > 0 )
{ {
(*mpOut) << TSS_GetString( cTW, tw::STR_CHANGED ) << _T(":") << endl; (*mpOut) << TSS_GetString( cTW, tw::STR_CHANGED ) << _T(":") << endl;

View File

@ -1557,15 +1557,11 @@ int cTWAModeExamine::Execute(cErrorQueue* pQueue)
iUserNotify::GetInstance()->Notify(iUserNotify::V_NORMAL, TSS_GetString(cTWAdmin, twadmin::STR_KEYS_DECRYPT ).c_str()); iUserNotify::GetInstance()->Notify(iUserNotify::V_NORMAL, TSS_GetString(cTWAdmin, twadmin::STR_KEYS_DECRYPT ).c_str());
iUserNotify::GetInstance()->Notify(iUserNotify::V_NORMAL, TSS_GetString(cTW, tw::STR_NEWLINE ).c_str()); iUserNotify::GetInstance()->Notify(iUserNotify::V_NORMAL, TSS_GetString(cTW, tw::STR_NEWLINE ).c_str());
bool siteDecrypts = false, localDecrypts = false;
if (siteKey.KeysLoaded()) if (siteKey.KeysLoaded())
try try
{ {
if (manip.TestDecryption(*siteKey.GetPublicKey(), false) != false) if (manip.TestDecryption(*siteKey.GetPublicKey(), false) != false)
{ {
siteDecrypts = true;
iUserNotify::GetInstance()->Notify(iUserNotify::V_SILENT, TSS_GetString(cTWAdmin, twadmin::STR_SITEKEYFILE ).c_str()); iUserNotify::GetInstance()->Notify(iUserNotify::V_SILENT, TSS_GetString(cTWAdmin, twadmin::STR_SITEKEYFILE ).c_str());
iUserNotify::GetInstance()->Notify(iUserNotify::V_SILENT, cDisplayEncoder::EncodeInline( mSiteKeyFile ).c_str()); iUserNotify::GetInstance()->Notify(iUserNotify::V_SILENT, cDisplayEncoder::EncodeInline( mSiteKeyFile ).c_str());
@ -1579,7 +1575,6 @@ int cTWAModeExamine::Execute(cErrorQueue* pQueue)
{ {
if (manip.TestDecryption(*localKey.GetPublicKey(), false) != false) if (manip.TestDecryption(*localKey.GetPublicKey(), false) != false)
{ {
localDecrypts = true;
iUserNotify::GetInstance()->Notify(iUserNotify::V_SILENT, TSS_GetString(cTWAdmin, twadmin::STR_LOCALKEYFILE ).c_str()); iUserNotify::GetInstance()->Notify(iUserNotify::V_SILENT, TSS_GetString(cTWAdmin, twadmin::STR_LOCALKEYFILE ).c_str());
iUserNotify::GetInstance()->Notify(iUserNotify::V_SILENT, cDisplayEncoder::EncodeInline( mLocalKeyFile ).c_str()); iUserNotify::GetInstance()->Notify(iUserNotify::V_SILENT, cDisplayEncoder::EncodeInline( mLocalKeyFile ).c_str());
@ -1834,7 +1829,6 @@ int cTWAModeGenerateKeys::Execute(cErrorQueue* pQueue)
// //
if(! bPrintedPassphraseHint) if(! bPrintedPassphraseHint)
{ {
bPrintedPassphraseHint = true;
iUserNotify::GetInstance()->Notify( iUserNotify::V_NORMAL, TSS_GetString(cTWAdmin, twadmin::STR_PASSPHRASE_HINT).c_str() ); iUserNotify::GetInstance()->Notify( iUserNotify::V_NORMAL, TSS_GetString(cTWAdmin, twadmin::STR_PASSPHRASE_HINT).c_str() );
} }
@ -2162,7 +2156,6 @@ int cTWAModeChangePassphrases::Execute(cErrorQueue* pQueue)
// //
if(! bPrintedPassphraseHint) if(! bPrintedPassphraseHint)
{ {
bPrintedPassphraseHint = true;
iUserNotify::GetInstance()->Notify( iUserNotify::V_NORMAL, TSS_GetString(cTWAdmin, twadmin::STR_PASSPHRASE_HINT).c_str() ); iUserNotify::GetInstance()->Notify( iUserNotify::V_NORMAL, TSS_GetString(cTWAdmin, twadmin::STR_PASSPHRASE_HINT).c_str() );
} }