Browse Source

Merge pull request #417 from dpogue/coverity

Coverity Fixes
Adam Johnson 11 years ago
parent
commit
eefa389be1
  1. 2
      Sources/Plasma/FeatureLib/pfPython/pyGUIControlMultiLineEdit.cpp
  2. 2
      Sources/Plasma/FeatureLib/pfPython/pyGUIControlMultiLineEdit.h
  3. 2
      Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBox.cpp
  4. 2
      Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBox.h
  5. 73
      Sources/Plasma/NucleusLib/pnEncryption/plChecksum.cpp
  6. 32
      Sources/Plasma/NucleusLib/pnEncryption/plChecksum.h

2
Sources/Plasma/FeatureLib/pfPython/pyGUIControlMultiLineEdit.cpp

@ -559,7 +559,7 @@ void pyGUIControlMultiLineEdit::DeleteLinesFromTop( int lines )
} }
} }
uint32_t pyGUIControlMultiLineEdit::GetFontSize() uint32_t pyGUIControlMultiLineEdit::GetFontSize() const
{ {
if (fGCkey) if (fGCkey)
{ {

2
Sources/Plasma/FeatureLib/pfPython/pyGUIControlMultiLineEdit.h

@ -111,7 +111,7 @@ public:
virtual void DeleteLinesFromTop( int lines ); virtual void DeleteLinesFromTop( int lines );
virtual uint32_t GetFontSize(); virtual uint32_t GetFontSize() const;
virtual void SetFontSize( uint32_t fontsize ); virtual void SetFontSize( uint32_t fontsize );
}; };

2
Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBox.cpp

@ -146,7 +146,7 @@ void pyGUIControlTextBox::SetForeColor( pyColor& color )
} }
PyObject* pyGUIControlTextBox::GetForeColor() PyObject* pyGUIControlTextBox::GetForeColor() const
{ {
if ( fGCkey ) if ( fGCkey )
{ {

2
Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBox.h

@ -88,7 +88,7 @@ public:
virtual void SetJustify( uint8_t justify ); virtual void SetJustify( uint8_t justify );
virtual uint8_t GetJustify(); virtual uint8_t GetJustify();
virtual PyObject* GetForeColor(); // returns pyColor virtual PyObject* GetForeColor() const; // returns pyColor
}; };
#endif // _pyGUIControlTextBox_h_ #endif // _pyGUIControlTextBox_h_

73
Sources/Plasma/NucleusLib/pnEncryption/plChecksum.cpp

@ -104,11 +104,11 @@ plChecksum::plChecksum(unsigned int bufsize, const char* buffer)
//============================================================================ //============================================================================
plMD5Checksum::plMD5Checksum(size_t size, uint8_t *buffer ) plMD5Checksum::plMD5Checksum(size_t size, uint8_t* buffer)
{ {
fValid = false; fValid = false;
Start(); Start();
AddTo( size, buffer ); AddTo(size, buffer);
Finish(); Finish();
} }
@ -117,41 +117,43 @@ plMD5Checksum::plMD5Checksum()
Clear(); Clear();
} }
plMD5Checksum::plMD5Checksum( const plMD5Checksum &rhs ) plMD5Checksum::plMD5Checksum(const plMD5Checksum& rhs)
{ {
memcpy( fChecksum, rhs.fChecksum, sizeof( fChecksum ) ); memset(&fContext, 0, sizeof(fContext));
memcpy(fChecksum, rhs.fChecksum, sizeof(fChecksum));
fValid = rhs.fValid; fValid = rhs.fValid;
} }
plMD5Checksum::plMD5Checksum( const plFileName &fileName ) plMD5Checksum::plMD5Checksum(const plFileName& fileName)
{ {
CalcFromFile( fileName ); CalcFromFile(fileName);
} }
plMD5Checksum::plMD5Checksum( hsStream* stream ) plMD5Checksum::plMD5Checksum(hsStream* stream)
{ {
CalcFromStream(stream); CalcFromStream(stream);
} }
void plMD5Checksum::Clear() void plMD5Checksum::Clear()
{ {
memset( fChecksum, 0, sizeof( fChecksum ) ); memset(&fContext, 0, sizeof(fContext));
memset(fChecksum, 0, sizeof(fChecksum));
fValid = false; fValid = false;
} }
void plMD5Checksum::CalcFromFile( const plFileName &fileName ) void plMD5Checksum::CalcFromFile(const plFileName& fileName)
{ {
hsUNIXStream s; hsUNIXStream s;
fValid = false; fValid = false;
if( s.Open(fileName) ) if (s.Open(fileName))
{ {
CalcFromStream(&s); CalcFromStream(&s);
s.Close(); s.Close();
} }
} }
void plMD5Checksum::CalcFromStream( hsStream* stream ) void plMD5Checksum::CalcFromStream(hsStream* stream)
{ {
uint32_t sPos = stream->GetPosition(); uint32_t sPos = stream->GetPosition();
unsigned loadLen = 1024 * 1024; unsigned loadLen = 1024 * 1024;
@ -159,8 +161,8 @@ void plMD5Checksum::CalcFromStream( hsStream* stream )
uint8_t *buf = new uint8_t[loadLen]; uint8_t *buf = new uint8_t[loadLen];
while(int read = stream->Read(loadLen, buf)) while (int read = stream->Read(loadLen, buf))
AddTo( read, buf ); AddTo(read, buf);
delete[] buf; delete[] buf;
Finish(); Finish();
@ -169,50 +171,51 @@ void plMD5Checksum::CalcFromStream( hsStream* stream )
void plMD5Checksum::Start() void plMD5Checksum::Start()
{ {
MD5_Init( &fContext ); MD5_Init(&fContext);
fValid = false; fValid = false;
} }
void plMD5Checksum::AddTo(size_t size, const uint8_t *buffer ) void plMD5Checksum::AddTo(size_t size, const uint8_t* buffer)
{ {
MD5_Update( &fContext, buffer, size ); MD5_Update(&fContext, buffer, size);
} }
void plMD5Checksum::Finish() void plMD5Checksum::Finish()
{ {
MD5_Final( fChecksum, &fContext ); MD5_Final(fChecksum, &fContext);
fValid = true; fValid = true;
memset(&fContext, 0, sizeof(fContext));
} }
const char *plMD5Checksum::GetAsHexString() const const char* plMD5Checksum::GetAsHexString() const
{ {
const int kHexStringSize = ( 2 * MD5_DIGEST_LENGTH ) + 1; const int kHexStringSize = (2 * MD5_DIGEST_LENGTH) + 1;
static char tempString[ kHexStringSize ]; static char tempString[kHexStringSize];
int i; int i;
char *ptr; char *ptr;
hsAssert( fValid, "Trying to get string version of invalid checksum" ); hsAssert(fValid, "Trying to get string version of invalid checksum");
for( i = 0, ptr = tempString; i < sizeof( fChecksum ); i++, ptr += 2 ) for (i = 0, ptr = tempString; i < sizeof(fChecksum); i++, ptr += 2)
sprintf( ptr, "%02x", fChecksum[ i ] ); sprintf(ptr, "%02x", fChecksum[i]);
*ptr = 0; *ptr = 0;
return tempString; return tempString;
} }
void plMD5Checksum::SetFromHexString( const char *string ) void plMD5Checksum::SetFromHexString(const char* string)
{ {
const char *ptr; const char *ptr;
int i; int i;
hsAssert( strlen( string ) == 2 * MD5_DIGEST_LENGTH, "Invalid string in MD5Checksum Set()" ); hsAssert(strlen(string) == 2 * MD5_DIGEST_LENGTH, "Invalid string in MD5Checksum Set()");
for( i = 0, ptr = string; i < sizeof( fChecksum ); i++, ptr += 2 ) for (i = 0, ptr = string; i < sizeof(fChecksum); i++, ptr += 2)
fChecksum[ i ] = ( IHexCharToInt( ptr[ 0 ] ) << 4 ) | IHexCharToInt( ptr[ 1 ] ); fChecksum[i] = (IHexCharToInt(ptr[0]) << 4) | IHexCharToInt(ptr[1]);
fValid = true; fValid = true;
} }
@ -223,14 +226,14 @@ void plMD5Checksum::SetValue(uint8_t* checksum)
memcpy(fChecksum, checksum, sizeof(fChecksum)); memcpy(fChecksum, checksum, sizeof(fChecksum));
} }
bool plMD5Checksum::operator==( const plMD5Checksum &rhs ) const bool plMD5Checksum::operator==(const plMD5Checksum& rhs) const
{ {
return (fValid && rhs.fValid && memcmp(fChecksum, rhs.fChecksum, sizeof(fChecksum)) == 0); return (fValid && rhs.fValid && memcmp(fChecksum, rhs.fChecksum, sizeof(fChecksum)) == 0);
} }
//============================================================================ //============================================================================
plSHAChecksum::plSHAChecksum(size_t size, uint8_t *buffer ) plSHAChecksum::plSHAChecksum(size_t size, uint8_t* buffer)
{ {
fValid = false; fValid = false;
Start(); Start();
@ -245,6 +248,7 @@ plSHAChecksum::plSHAChecksum()
plSHAChecksum::plSHAChecksum(const plSHAChecksum& rhs) plSHAChecksum::plSHAChecksum(const plSHAChecksum& rhs)
{ {
memset(&fContext, 0, sizeof(fContext));
memcpy(fChecksum, rhs.fChecksum, sizeof(fChecksum)); memcpy(fChecksum, rhs.fChecksum, sizeof(fChecksum));
fValid = rhs.fValid; fValid = rhs.fValid;
} }
@ -261,6 +265,7 @@ plSHAChecksum::plSHAChecksum(hsStream* stream)
void plSHAChecksum::Clear() void plSHAChecksum::Clear()
{ {
memset(&fContext, 0, sizeof(fContext));
memset(fChecksum, 0, sizeof(fChecksum)); memset(fChecksum, 0, sizeof(fChecksum));
fValid = false; fValid = false;
} }
@ -310,9 +315,10 @@ void plSHAChecksum::Finish()
{ {
SHA_Final(fChecksum, &fContext); SHA_Final(fChecksum, &fContext);
fValid = true; fValid = true;
memset(&fContext, 0, sizeof(fContext));
} }
const char *plSHAChecksum::GetAsHexString() const const char* plSHAChecksum::GetAsHexString() const
{ {
const int kHexStringSize = (2 * SHA_DIGEST_LENGTH) + 1; const int kHexStringSize = (2 * SHA_DIGEST_LENGTH) + 1;
static char tempString[kHexStringSize]; static char tempString[kHexStringSize];
@ -356,7 +362,7 @@ bool plSHAChecksum::operator==(const plSHAChecksum& rhs) const
//============================================================================ //============================================================================
plSHA1Checksum::plSHA1Checksum(size_t size, uint8_t *buffer ) plSHA1Checksum::plSHA1Checksum(size_t size, uint8_t* buffer)
{ {
fValid = false; fValid = false;
Start(); Start();
@ -371,6 +377,7 @@ plSHA1Checksum::plSHA1Checksum()
plSHA1Checksum::plSHA1Checksum(const plSHA1Checksum& rhs) plSHA1Checksum::plSHA1Checksum(const plSHA1Checksum& rhs)
{ {
memset(&fContext, 0, sizeof(fContext));
memcpy(fChecksum, rhs.fChecksum, sizeof(fChecksum)); memcpy(fChecksum, rhs.fChecksum, sizeof(fChecksum));
fValid = rhs.fValid; fValid = rhs.fValid;
} }
@ -389,6 +396,7 @@ void plSHA1Checksum::Clear()
{ {
memset(fChecksum, 0, sizeof(fChecksum)); memset(fChecksum, 0, sizeof(fChecksum));
fValid = false; fValid = false;
memset(&fContext, 0, sizeof(fContext));
} }
void plSHA1Checksum::CalcFromFile(const plFileName& fileName) void plSHA1Checksum::CalcFromFile(const plFileName& fileName)
@ -436,9 +444,10 @@ void plSHA1Checksum::Finish()
{ {
SHA1_Final(fChecksum, &fContext); SHA1_Final(fChecksum, &fContext);
fValid = true; fValid = true;
memset(&fContext, 0, sizeof(fContext));
} }
const char *plSHA1Checksum::GetAsHexString() const const char* plSHA1Checksum::GetAsHexString() const
{ {
const int kHexStringSize = (2 * SHA_DIGEST_LENGTH) + 1; const int kHexStringSize = (2 * SHA_DIGEST_LENGTH) + 1;
static char tempString[kHexStringSize]; static char tempString[kHexStringSize];

32
Sources/Plasma/NucleusLib/pnEncryption/plChecksum.h

@ -70,35 +70,35 @@ class plMD5Checksum
uint8_t fChecksum[MD5_DIGEST_LENGTH]; uint8_t fChecksum[MD5_DIGEST_LENGTH];
public: public:
plMD5Checksum(size_t size, uint8_t *buffer); plMD5Checksum(size_t size, uint8_t* buffer);
plMD5Checksum(); plMD5Checksum();
plMD5Checksum(const plMD5Checksum &rhs); plMD5Checksum(const plMD5Checksum& rhs);
plMD5Checksum(const plFileName &fileName); plMD5Checksum(const plFileName& fileName);
plMD5Checksum(hsStream* stream); plMD5Checksum(hsStream* stream);
bool IsValid() const { return fValid; } bool IsValid() const { return fValid; }
void Clear(); void Clear();
void CalcFromFile(const plFileName &fileName); void CalcFromFile(const plFileName& fileName);
void CalcFromStream(hsStream* stream); void CalcFromStream(hsStream* stream);
void Start(); void Start();
void AddTo(size_t size, const uint8_t *buffer); void AddTo(size_t size, const uint8_t* buffer);
void Finish(); void Finish();
const uint8_t *GetValue() const { return fChecksum; } const uint8_t* GetValue() const { return fChecksum; }
size_t GetSize() const { return sizeof(fChecksum); } size_t GetSize() const { return sizeof(fChecksum); }
// Backdoor for cached checksums (ie, if you loaded it off disk) // Backdoor for cached checksums (ie, if you loaded it off disk)
void SetValue(uint8_t* checksum); void SetValue(uint8_t* checksum);
// Note: GetAsHexString() returns a pointer to a static string; // Note: GetAsHexString() returns a pointer to a static string;
// do not rely on the contents of this string between calls! // do not rely on the contents of this string between calls!
const char *GetAsHexString() const; const char* GetAsHexString() const;
void SetFromHexString( const char *string ); void SetFromHexString(const char* string);
bool operator==(const plMD5Checksum &rhs) const; bool operator==(const plMD5Checksum& rhs) const;
bool operator!=(const plMD5Checksum &rhs) const { return !operator==(rhs); } bool operator!=(const plMD5Checksum& rhs) const { return !operator==(rhs); }
}; };
/* A bunch of things might store either a SHA or a SHA1 checksum, this provides /* A bunch of things might store either a SHA or a SHA1 checksum, this provides

Loading…
Cancel
Save