From 93eb41b1fe0c9841d76650f3ca76680ac6a0baa6 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Sun, 12 Jul 2015 22:40:30 -0700 Subject: [PATCH] Fix some legitimate bugs found by Coverity which MAY IMPACT BEHAVIOR! --- .../Plasma/FeatureLib/pfConsoleCore/pfConsoleCmd.cpp | 4 ++-- Sources/Plasma/NucleusLib/inc/plProfileManager.cpp | 6 +++--- Sources/Plasma/NucleusLib/pnMessage/plNotifyMsg.cpp | 4 ++++ Sources/Plasma/PubUtilLib/plAudio/plDSoundBuffer.cpp | 11 +++++------ Sources/Plasma/PubUtilLib/plDrawable/plSpanInstance.h | 2 +- .../Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp | 4 ++-- Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h | 6 +++--- .../PubUtilLib/plInputCore/plAvatarInputInterface.cpp | 1 + Sources/Plasma/PubUtilLib/plSDL/plStateDataRecord.cpp | 2 +- Sources/Plasma/PubUtilLib/plSDL/plStateVariable.cpp | 2 ++ Sources/Tools/MaxConvert/plLightMapGen.cpp | 2 +- Sources/Tools/MaxExport/plExportDlg.cpp | 2 +- Sources/Tools/MaxMain/plComponentDlg.cpp | 4 ++-- 13 files changed, 28 insertions(+), 22 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleCmd.cpp b/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleCmd.cpp index 99589078..6778d596 100644 --- a/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleCmd.cpp +++ b/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleCmd.cpp @@ -428,8 +428,8 @@ void pfConsoleCmd::ICreateSignature(const char *paramList ) hsAssert( strlen( paramList ) < sizeof( params ), "Make the (#*$& params string larger!" ); hsStrcpy( params, paramList ); - fSignature.Empty(); - fSigLabels.Empty(); + fSignature.Reset(); + fSigLabels.Reset(); /// Loop through all the types given in the list ptr = params; diff --git a/Sources/Plasma/NucleusLib/inc/plProfileManager.cpp b/Sources/Plasma/NucleusLib/inc/plProfileManager.cpp index b9bc668e..cbe16196 100644 --- a/Sources/Plasma/NucleusLib/inc/plProfileManager.cpp +++ b/Sources/Plasma/NucleusLib/inc/plProfileManager.cpp @@ -237,12 +237,12 @@ void plProfileBase::IPrintValue(uint64_t value, char* buf, bool printType) if (value > (1024*1000)) sprintf(buf, "%.2f MB", float(value) / (1024.f * 1024.f)); else if (value > 1024) - sprintf(buf, "%d KB", value / 1024); + sprintf(buf, "%llu KB", value / 1024); else - sprintf(buf, "%d b", value); + sprintf(buf, "%llu b", value); } else - sprintf(buf, "%u", value); + sprintf(buf, "%llu", value); } } diff --git a/Sources/Plasma/NucleusLib/pnMessage/plNotifyMsg.cpp b/Sources/Plasma/NucleusLib/pnMessage/plNotifyMsg.cpp index b959ccb4..c2c32b98 100644 --- a/Sources/Plasma/NucleusLib/pnMessage/plNotifyMsg.cpp +++ b/Sources/Plasma/NucleusLib/pnMessage/plNotifyMsg.cpp @@ -147,6 +147,7 @@ void plNotifyMsg::AddEvent( proEventData* ed ) proCoopEventData *evt = (proCoopEventData *)ed; AddCoopEvent( evt->fID, evt->fSerial); } + break; case proEventData::kControlKey: { @@ -200,16 +201,19 @@ void plNotifyMsg::AddEvent( proEventData* ed ) proOfferLinkingBookEventData* evt = (proOfferLinkingBookEventData*)ed; AddOfferBookEvent(evt->offerer, evt->targetAge, evt->offeree); } + break; case proEventData::kBook: { proBookEventData* evt = (proBookEventData*)ed; AddBookEvent( evt->fEvent, evt->fLinkID ); } + break; case proEventData::kClimbingBlockerHit: { proClimbingBlockerHitEventData* evt = (proClimbingBlockerHitEventData*)ed; AddHitClimbingBlockerEvent(evt->fBlockerKey); } + break; } } diff --git a/Sources/Plasma/PubUtilLib/plAudio/plDSoundBuffer.cpp b/Sources/Plasma/PubUtilLib/plAudio/plDSoundBuffer.cpp index ec78a270..237e6cb7 100644 --- a/Sources/Plasma/PubUtilLib/plAudio/plDSoundBuffer.cpp +++ b/Sources/Plasma/PubUtilLib/plAudio/plDSoundBuffer.cpp @@ -283,7 +283,7 @@ bool plDSoundBuffer::SetupStreamingSource(plAudioFileReader *stream) alSourcef(source, AL_ROLLOFF_FACTOR, 0.3048); - alGetError(); + error = alGetError(); if( error != AL_NO_ERROR ) { return false; @@ -348,7 +348,7 @@ bool plDSoundBuffer::SetupStreamingSource(void *data, unsigned bytes) SetScalarVolume(0); alSourcef(source, AL_ROLLOFF_FACTOR, 0.3048); - alGetError(); + error = alGetError(); if( error != AL_NO_ERROR ) { return false; @@ -478,8 +478,7 @@ bool plDSoundBuffer::GetAvailableBufferId(unsigned *bufferId) bool plDSoundBuffer::SetupVoiceSource() { - ALenum error; - alGetError(); + ALenum error = alGetError(); // Generate AL Buffers alGenBuffers( STREAMING_BUFFERS, streamingBuffers ); @@ -507,13 +506,13 @@ bool plDSoundBuffer::SetupVoiceSource() SetScalarVolume(0); alSourcef(source, AL_ROLLOFF_FACTOR, 0.3048); - alGetError(); + error = alGetError(); if( error != AL_NO_ERROR ) { return false; } alSourcei(source, AL_BUFFER, 0); - alGetError(); + error = alGetError(); //alSourcei(source, AL_PITCH, 0); // dont queue any buffers here diff --git a/Sources/Plasma/PubUtilLib/plDrawable/plSpanInstance.h b/Sources/Plasma/PubUtilLib/plDrawable/plSpanInstance.h index e8ac008e..34397005 100644 --- a/Sources/Plasma/PubUtilLib/plDrawable/plSpanInstance.h +++ b/Sources/Plasma/PubUtilLib/plDrawable/plSpanInstance.h @@ -171,7 +171,7 @@ public: } static uint16_t ColStrideFromEncoding(const plSpanEncoding& encoding) { - switch(encoding.fCode & plSpanEncoding::kPosMask) + switch(encoding.fCode & plSpanEncoding::kColMask) { case plSpanEncoding::kColNone: return 0; diff --git a/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp b/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp index f22e327e..130936e9 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp +++ b/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp @@ -331,14 +331,14 @@ void plDynamicTextMap::SetInitBuffer( uint32_t *buffer ) //// CopyFrom ///////////////////////////////////////////////////////////////// -void plDynamicTextMap::CopyFrom( plMipmap *source ) +void plDynamicTextMap::CopyFrom(const plMipmap *source) { hsAssert( false, "Copying plDynamicTextMaps is not supported." ); } //// Clone //////////////////////////////////////////////////////////////////// -plMipmap *plDynamicTextMap::Clone( void ) +plMipmap *plDynamicTextMap::Clone() const { static bool alreadyWarned = false; diff --git a/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h b/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h index ad47bab3..01bc12a1 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h +++ b/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h @@ -130,9 +130,9 @@ class plDynamicTextMap : public plMipmap virtual uint8_t GetNumLevels( void ) const { return 1; } - virtual void Colorize( void ) { ; } - virtual plMipmap *Clone( void ); - virtual void CopyFrom( plMipmap *source ); + void Colorize() override { } + plMipmap *Clone() const override; + void CopyFrom(const plMipmap *source) override; /// Operations to perform on the text block diff --git a/Sources/Plasma/PubUtilLib/plInputCore/plAvatarInputInterface.cpp b/Sources/Plasma/PubUtilLib/plInputCore/plAvatarInputInterface.cpp index a6a1744e..56db844c 100644 --- a/Sources/Plasma/PubUtilLib/plInputCore/plAvatarInputInterface.cpp +++ b/Sources/Plasma/PubUtilLib/plInputCore/plAvatarInputInterface.cpp @@ -471,6 +471,7 @@ bool plAvatarInputInterface::IHandleCtrlCmd( plCtrlCmd *cmd ) fCurrentCursor = kCursorHidden; else fCurrentCursor = kCursorUp; + return true; case S_SET_LADDER_CONTROL: if( cmd->fControlActivated ) ISetLadderMap(); diff --git a/Sources/Plasma/PubUtilLib/plSDL/plStateDataRecord.cpp b/Sources/Plasma/PubUtilLib/plSDL/plStateDataRecord.cpp index 8684c418..7f2b895c 100644 --- a/Sources/Plasma/PubUtilLib/plSDL/plStateDataRecord.cpp +++ b/Sources/Plasma/PubUtilLib/plSDL/plStateDataRecord.cpp @@ -838,7 +838,7 @@ void plStateDataRecord::TimeStampDirtyVars() // set nested vars for(i=0;iIsDirty() ) + if ( fSDVarsList[i]->IsDirty() ) fSDVarsList[i]->TimeStamp(); } } diff --git a/Sources/Plasma/PubUtilLib/plSDL/plStateVariable.cpp b/Sources/Plasma/PubUtilLib/plSDL/plStateVariable.cpp index 0fefdb9d..b2c1e2dd 100644 --- a/Sources/Plasma/PubUtilLib/plSDL/plStateVariable.cpp +++ b/Sources/Plasma/PubUtilLib/plSDL/plStateVariable.cpp @@ -839,6 +839,7 @@ bool plSimpleStateVariable::IConvertFromShort(plVarDescriptor::Type newType) delete [] fS; fI = newI; } + break; case plVarDescriptor::kByte: { uint8_t* newBy = new uint8_t[fVar.GetCount()]; @@ -897,6 +898,7 @@ bool plSimpleStateVariable::IConvertFromByte(plVarDescriptor::Type newType) delete [] fBy; fI = newI; } + break; case plVarDescriptor::kShort: { short* newS = new short[fVar.GetCount()]; diff --git a/Sources/Tools/MaxConvert/plLightMapGen.cpp b/Sources/Tools/MaxConvert/plLightMapGen.cpp index 205a4663..a9cb4f9b 100644 --- a/Sources/Tools/MaxConvert/plLightMapGen.cpp +++ b/Sources/Tools/MaxConvert/plLightMapGen.cpp @@ -1587,7 +1587,7 @@ bool plLightMapGen::ISelectBitmapDimension(plMaxNode* node, const hsMatrix44& l2 if( dvDr > 0 ) { - fHeight = (int)(kTexPerFoot / duDr); + fHeight = (int)(kTexPerFoot / dvDr); if( fHeight > kMaxSize ) fHeight = kMaxSize; diff --git a/Sources/Tools/MaxExport/plExportDlg.cpp b/Sources/Tools/MaxExport/plExportDlg.cpp index 5af2fb0e..050c8bc5 100644 --- a/Sources/Tools/MaxExport/plExportDlg.cpp +++ b/Sources/Tools/MaxExport/plExportDlg.cpp @@ -489,7 +489,7 @@ void plExportDlgImp::StartAutoExport() char outputDir[MAX_PATH]; GetPrivateProfileString("Settings", "MaxOutputDir", "", outputDir, sizeof(outputDir), configFile); - if (inputDir[0] == '\0' || outputDir == '\0') + if (inputDir[0] == '\0' || outputDir[0] == '\0') return; fAutoExporting = true; diff --git a/Sources/Tools/MaxMain/plComponentDlg.cpp b/Sources/Tools/MaxMain/plComponentDlg.cpp index d7f95284..c9384809 100644 --- a/Sources/Tools/MaxMain/plComponentDlg.cpp +++ b/Sources/Tools/MaxMain/plComponentDlg.cpp @@ -174,8 +174,8 @@ void plComponentDlg::IPositionControl(HWND hControl, int hDiff, int wDiff, int f RECT rect; GetWindowRect(hControl, &rect); - hsAssert(!((flags & kMoveX) & (flags & kResizeX)), "Moving AND resizing in X in IPositionControl"); - hsAssert(!((flags & kMoveY) & (flags & kResizeY)), "Moving AND resizing in Y in IPositionControl"); + hsAssert(!((flags & kMoveX) && (flags & kResizeX)), "Moving AND resizing in X in IPositionControl"); + hsAssert(!((flags & kMoveY) && (flags & kResizeY)), "Moving AND resizing in Y in IPositionControl"); if (flags & kMoveX || flags & kMoveY) {