Issue found by PVS Studio:

Several instances where we utilize a pointer variable without properly testing that they aren't null first.
This commit is contained in:
Areloch 2015-07-28 23:19:59 -05:00
parent b24bdfbc8b
commit 3a18819e1e
9 changed files with 44 additions and 37 deletions

View file

@ -502,7 +502,7 @@ void ConvexShape::prepRenderImage( SceneRenderState *state )
} }
*/ */
if ( mVertexBuffer.isNull() ) if ( mVertexBuffer.isNull() || !state)
return; return;
// If we don't have a material instance after the override then // If we don't have a material instance after the override then

View file

@ -269,7 +269,7 @@ void RenderMeshExample::prepRenderImage( SceneRenderState *state )
createGeometry(); createGeometry();
// If we have no material then skip out. // If we have no material then skip out.
if ( !mMaterialInst ) if ( !mMaterialInst || !state)
return; return;
// If we don't have a material instance after the override then // If we don't have a material instance after the override then

View file

@ -847,12 +847,13 @@ DefineEngineFunction(linkNamespaces, bool, ( String childNSName, String parentNS
Namespace *childNS = Namespace::find(childNSSTE); Namespace *childNS = Namespace::find(childNSSTE);
Namespace *parentNS = Namespace::find(parentNSSTE); Namespace *parentNS = Namespace::find(parentNSSTE);
Namespace *currentParent = childNS->getParent();
if (!childNS) if (!childNS)
{ {
return false; return false;
} }
Namespace *currentParent = childNS->getParent();
// Link to new NS if applicable // Link to new NS if applicable

View file

@ -66,7 +66,7 @@ void GFXPCD3D9Device::createDirect3D9(LPDIRECT3D9 &d3d9, LPDIRECT3D9EX &d3d9ex)
if (pfnCreate9Ex) if (pfnCreate9Ex)
{ {
if (!FAILED(pfnCreate9Ex(D3D_SDK_VERSION, &d3d9ex)) && d3d9ex) if (d3d9ex && !FAILED(pfnCreate9Ex(D3D_SDK_VERSION, &d3d9ex)))
d3d9ex->QueryInterface(__uuidof(IDirect3D9), reinterpret_cast<void **>(&d3d9)); d3d9ex->QueryInterface(__uuidof(IDirect3D9), reinterpret_cast<void **>(&d3d9));
} }

View file

@ -1212,7 +1212,7 @@ void GuiWindowCtrl::onMouseUp(const GuiEvent &event)
// We're either moving out of a collapse group or moving to another one // We're either moving out of a collapse group or moving to another one
// Not valid for windows not previously in a group // Not valid for windows not previously in a group
if( mCollapseGroup >= 0 && if( mCollapseGroup >= 0 &&
( snapType == -1 || ( snapType >= 0 && mCollapseGroup != hitWindow->mCollapseGroup) ) ) (snapType == -1 || (hitWindow && snapType >= 0 && mCollapseGroup != hitWindow->mCollapseGroup)))
moveFromCollapseGroup(); moveFromCollapseGroup();
// No window to connect to // No window to connect to

View file

@ -1755,41 +1755,48 @@ void GuiControl::write(Stream &stream, U32 tabStop, U32 flags)
{ {
//note: this will return false if either we, or any of our parents, are non-save controls //note: this will return false if either we, or any of our parents, are non-save controls
bool bCanSave = ( flags & IgnoreCanSave ) || ( flags & NoCheckParentCanSave && getCanSave() ) || getCanSaveParent(); bool bCanSave = ( flags & IgnoreCanSave ) || ( flags & NoCheckParentCanSave && getCanSave() ) || getCanSaveParent();
StringTableEntry steName = mAddGroup->getInternalName();
if(bCanSave && mAddGroup && (steName != NULL) && (steName != StringTable->insert("null")) && getName() ) if (bCanSave && mAddGroup)
{ {
MutexHandle handle; StringTableEntry steName = mAddGroup->getInternalName();
handle.lock(mMutex);
// export selected only? if ((steName != NULL) && (steName != StringTable->insert("null")) && getName())
if((flags & SelectedOnly) && !isSelected())
{ {
for(U32 i = 0; i < size(); i++) MutexHandle handle;
(*this)[i]->write(stream, tabStop, flags); handle.lock(mMutex);
// export selected only?
if ((flags & SelectedOnly) && !isSelected())
{
for (U32 i = 0; i < size(); i++)
(*this)[i]->write(stream, tabStop, flags);
return;
}
stream.writeTabs(tabStop);
char buffer[1024];
dSprintf(buffer, sizeof(buffer), "new %s(%s,%s) {\r\n", getClassName(), getName() ? getName() : "", mAddGroup->getInternalName());
stream.write(dStrlen(buffer), buffer);
writeFields(stream, tabStop + 1);
if (size())
{
stream.write(2, "\r\n");
for (U32 i = 0; i < size(); i++)
(*this)[i]->write(stream, tabStop + 1, flags);
}
stream.writeTabs(tabStop);
stream.write(4, "};\r\n");
return; return;
} }
stream.writeTabs(tabStop);
char buffer[1024];
dSprintf(buffer, sizeof(buffer), "new %s(%s,%s) {\r\n", getClassName(), getName() ? getName() : "", mAddGroup->getInternalName());
stream.write(dStrlen(buffer), buffer);
writeFields(stream, tabStop + 1);
if(size())
{
stream.write(2, "\r\n");
for(U32 i = 0; i < size(); i++)
(*this)[i]->write(stream, tabStop + 1, flags);
}
stream.writeTabs(tabStop);
stream.write(4, "};\r\n");
} }
else if (bCanSave)
if (bCanSave)
Parent::write( stream, tabStop, flags ); Parent::write( stream, tabStop, flags );
} }
//============================================================================= //=============================================================================

View file

@ -2655,7 +2655,7 @@ void WorldEditor::renderScene( const RectI &updateRect )
// Probably should test the entire icon screen-rect instead of just the centerpoint // Probably should test the entire icon screen-rect instead of just the centerpoint
// but would need to move some code from renderScreenObj to here. // but would need to move some code from renderScreenObj to here.
if ( mDragSelect ) if (mDragSelect && selection)
if ( mDragRect.pointInRect(sPosI) && !selection->objInSet(obj) ) if ( mDragRect.pointInRect(sPosI) && !selection->objInSet(obj) )
mDragSelected->addObject(obj); mDragSelected->addObject(obj);

View file

@ -737,7 +737,7 @@ void PostEffect::_setupConstants( const SceneRenderState *state )
mShaderConsts->set( mMatPrevScreenToWorldSC, tempMat ); mShaderConsts->set( mMatPrevScreenToWorldSC, tempMat );
} }
if ( mAmbientColorSC->isValid() ) if (mAmbientColorSC->isValid() && state)
{ {
const ColorF &sunlight = state->getAmbientLightColor(); const ColorF &sunlight = state->getAmbientLightColor();
Point3F ambientColor( sunlight.red, sunlight.green, sunlight.blue ); Point3F ambientColor( sunlight.red, sunlight.green, sunlight.blue );

View file

@ -203,12 +203,11 @@ void RenderPrePassMgr::addElement( RenderInst *inst )
matInst = static_cast<MeshRenderInst*>(inst)->matInst; matInst = static_cast<MeshRenderInst*>(inst)->matInst;
// Skip decals if they don't have normal maps. // Skip decals if they don't have normal maps.
if ( isDecalMeshInst && !matInst->hasNormalMap() ) if (!matInst || isDecalMeshInst && !matInst->hasNormalMap())
return; return;
// If its a custom material and it refracts... skip it. // If its a custom material and it refracts... skip it.
if ( matInst && if ( matInst->isCustomMaterial() &&
matInst->isCustomMaterial() &&
static_cast<CustomMaterial*>( matInst->getMaterial() )->mRefract ) static_cast<CustomMaterial*>( matInst->getMaterial() )->mRefract )
return; return;