From d29024dd8b072501c923382d57863a62f5c5fd49 Mon Sep 17 00:00:00 2001 From: baldurk Date: Sun, 5 Oct 2014 18:46:39 +0100 Subject: [PATCH] [Refs #87: Static Analysis] Handle paranoid case of NULL parameters --- .../driver/d3d11/d3d11_context1_wrap.cpp | 54 ++++++++++++------- renderdoc/driver/d3d11/d3d11_context_wrap.cpp | 52 ++++++++++-------- 2 files changed, 65 insertions(+), 41 deletions(-) diff --git a/renderdoc/driver/d3d11/d3d11_context1_wrap.cpp b/renderdoc/driver/d3d11/d3d11_context1_wrap.cpp index af3f57931..26010f3ee 100644 --- a/renderdoc/driver/d3d11/d3d11_context1_wrap.cpp +++ b/renderdoc/driver/d3d11/d3d11_context1_wrap.cpp @@ -578,10 +578,13 @@ void WrappedID3D11DeviceContext::VSSetConstantBuffers1(UINT StartSlot, UINT NumB ID3D11Buffer *bufs[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT] = {0}; for(UINT i=0; i < NumBuffers; i++) { - if(ppConstantBuffers[i] && m_State >= WRITING_CAPFRAME) - MarkResourceReferenced(GetIDForResource(ppConstantBuffers[i]), eFrameRef_Read); + if(ppConstantBuffers && ppConstantBuffers[i]) + { + if(m_State >= WRITING_CAPFRAME) + MarkResourceReferenced(GetIDForResource(ppConstantBuffers[i]), eFrameRef_Read); - bufs[i] = UNWRAP(WrappedID3D11Buffer, ppConstantBuffers[i]); + bufs[i] = UNWRAP(WrappedID3D11Buffer, ppConstantBuffers[i]); + } } m_pRealContext1->VSSetConstantBuffers1(StartSlot, NumBuffers, bufs, pFirstConstant, pNumConstants); @@ -676,10 +679,13 @@ void WrappedID3D11DeviceContext::HSSetConstantBuffers1(UINT StartSlot, UINT NumB ID3D11Buffer *bufs[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT] = {0}; for(UINT i=0; i < NumBuffers; i++) { - if(ppConstantBuffers[i] && m_State >= WRITING_CAPFRAME) - MarkResourceReferenced(GetIDForResource(ppConstantBuffers[i]), eFrameRef_Read); + if(ppConstantBuffers && ppConstantBuffers[i]) + { + if(m_State >= WRITING_CAPFRAME) + MarkResourceReferenced(GetIDForResource(ppConstantBuffers[i]), eFrameRef_Read); - bufs[i] = UNWRAP(WrappedID3D11Buffer, ppConstantBuffers[i]); + bufs[i] = UNWRAP(WrappedID3D11Buffer, ppConstantBuffers[i]); + } } m_pRealContext1->HSSetConstantBuffers1(StartSlot, NumBuffers, bufs, pFirstConstant, pNumConstants); @@ -774,10 +780,13 @@ void WrappedID3D11DeviceContext::DSSetConstantBuffers1(UINT StartSlot, UINT NumB ID3D11Buffer *bufs[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT] = {0}; for(UINT i=0; i < NumBuffers; i++) { - if(ppConstantBuffers[i] && m_State >= WRITING_CAPFRAME) - MarkResourceReferenced(GetIDForResource(ppConstantBuffers[i]), eFrameRef_Read); + if(ppConstantBuffers && ppConstantBuffers[i]) + { + if(m_State >= WRITING_CAPFRAME) + MarkResourceReferenced(GetIDForResource(ppConstantBuffers[i]), eFrameRef_Read); - bufs[i] = UNWRAP(WrappedID3D11Buffer, ppConstantBuffers[i]); + bufs[i] = UNWRAP(WrappedID3D11Buffer, ppConstantBuffers[i]); + } } m_pRealContext1->DSSetConstantBuffers1(StartSlot, NumBuffers, bufs, pFirstConstant, pNumConstants); @@ -872,10 +881,13 @@ void WrappedID3D11DeviceContext::GSSetConstantBuffers1(UINT StartSlot, UINT NumB ID3D11Buffer *bufs[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT] = {0}; for(UINT i=0; i < NumBuffers; i++) { - if(ppConstantBuffers[i] && m_State >= WRITING_CAPFRAME) - MarkResourceReferenced(GetIDForResource(ppConstantBuffers[i]), eFrameRef_Read); + if(ppConstantBuffers && ppConstantBuffers[i]) + { + if(m_State >= WRITING_CAPFRAME) + MarkResourceReferenced(GetIDForResource(ppConstantBuffers[i]), eFrameRef_Read); - bufs[i] = UNWRAP(WrappedID3D11Buffer, ppConstantBuffers[i]); + bufs[i] = UNWRAP(WrappedID3D11Buffer, ppConstantBuffers[i]); + } } m_pRealContext1->GSSetConstantBuffers1(StartSlot, NumBuffers, bufs, pFirstConstant, pNumConstants); @@ -970,10 +982,13 @@ void WrappedID3D11DeviceContext::PSSetConstantBuffers1(UINT StartSlot, UINT NumB ID3D11Buffer *bufs[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT] = {0}; for(UINT i=0; i < NumBuffers; i++) { - if(ppConstantBuffers[i] && m_State >= WRITING_CAPFRAME) - MarkResourceReferenced(GetIDForResource(ppConstantBuffers[i]), eFrameRef_Read); + if(ppConstantBuffers && ppConstantBuffers[i]) + { + if(m_State >= WRITING_CAPFRAME) + MarkResourceReferenced(GetIDForResource(ppConstantBuffers[i]), eFrameRef_Read); - bufs[i] = UNWRAP(WrappedID3D11Buffer, ppConstantBuffers[i]); + bufs[i] = UNWRAP(WrappedID3D11Buffer, ppConstantBuffers[i]); + } } m_pRealContext1->PSSetConstantBuffers1(StartSlot, NumBuffers, bufs, pFirstConstant, pNumConstants); @@ -1068,10 +1083,13 @@ void WrappedID3D11DeviceContext::CSSetConstantBuffers1(UINT StartSlot, UINT NumB ID3D11Buffer *bufs[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT] = {0}; for(UINT i=0; i < NumBuffers; i++) { - if(ppConstantBuffers[i] && m_State >= WRITING_CAPFRAME) - MarkResourceReferenced(GetIDForResource(ppConstantBuffers[i]), eFrameRef_Read); + if(ppConstantBuffers && ppConstantBuffers[i]) + { + if(m_State >= WRITING_CAPFRAME) + MarkResourceReferenced(GetIDForResource(ppConstantBuffers[i]), eFrameRef_Read); - bufs[i] = UNWRAP(WrappedID3D11Buffer, ppConstantBuffers[i]); + bufs[i] = UNWRAP(WrappedID3D11Buffer, ppConstantBuffers[i]); + } } m_pRealContext1->CSSetConstantBuffers1(StartSlot, NumBuffers, bufs, pFirstConstant, pNumConstants); diff --git a/renderdoc/driver/d3d11/d3d11_context_wrap.cpp b/renderdoc/driver/d3d11/d3d11_context_wrap.cpp index fe1e6225b..c67baadbb 100644 --- a/renderdoc/driver/d3d11/d3d11_context_wrap.cpp +++ b/renderdoc/driver/d3d11/d3d11_context_wrap.cpp @@ -1940,19 +1940,22 @@ void WrappedID3D11DeviceContext::SOSetTargets(UINT NumBuffers, ID3D11Buffer *con ID3D11Buffer *bufs[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT] = {0}; for(UINT i=0; i < NumBuffers; i++) { - // technically this isn't dirty until the draw call, but let's be conservative - // to avoid having to track "possibly" dirty resources. - // Besides, it's unlikely an application will set an output then not draw to it - if(ppSOTargets[i] && m_State >= WRITING_CAPFRAME) + if(ppSOTargets && ppSOTargets[i]) { - MarkResourceReferenced(GetIDForResource(ppSOTargets[i]), eFrameRef_Write); - - if(m_State == WRITING_CAPFRAME) - m_MissingTracks.insert(GetIDForResource(ppSOTargets[i])); - if(m_State == WRITING_IDLE) - m_pDevice->GetResourceManager()->MarkDirtyResource(GetIDForResource(ppSOTargets[i])); + // technically this isn't dirty until the draw call, but let's be conservative + // to avoid having to track "possibly" dirty resources. + // Besides, it's unlikely an application will set an output then not draw to it + if(m_State >= WRITING_CAPFRAME) + { + MarkResourceReferenced(GetIDForResource(ppSOTargets[i]), eFrameRef_Write); + + if(m_State == WRITING_CAPFRAME) + m_MissingTracks.insert(GetIDForResource(ppSOTargets[i])); + if(m_State == WRITING_IDLE) + m_pDevice->GetResourceManager()->MarkDirtyResource(GetIDForResource(ppSOTargets[i])); + } + bufs[i] = UNWRAP(WrappedID3D11Buffer, ppSOTargets[i]); } - bufs[i] = UNWRAP(WrappedID3D11Buffer, ppSOTargets[i]); } m_pRealContext->SOSetTargets(NumBuffers, bufs, pOffsets); @@ -2733,19 +2736,22 @@ void WrappedID3D11DeviceContext::OMSetRenderTargets(UINT NumViews, ID3D11RenderT for(UINT i=0; i < NumViews; i++) { - if(ppRenderTargetViews[i] && m_State >= WRITING) + if(ppRenderTargetViews && ppRenderTargetViews[i]) { - ID3D11Resource *res = NULL; - ppRenderTargetViews[i]->GetResource(&res); - // technically this isn't dirty until the draw call, but let's be conservative - // to avoid having to track "possibly" dirty resources. - // Besides, it's unlikely an application will set an output then not draw to it - if(m_State == WRITING_IDLE) - m_pDevice->GetResourceManager()->MarkDirtyResource(GetIDForResource(res)); - SAFE_RELEASE(res); - } + if(m_State >= WRITING) + { + ID3D11Resource *res = NULL; + ppRenderTargetViews[i]->GetResource(&res); + // technically this isn't dirty until the draw call, but let's be conservative + // to avoid having to track "possibly" dirty resources. + // Besides, it's unlikely an application will set an output then not draw to it + if(m_State == WRITING_IDLE) + m_pDevice->GetResourceManager()->MarkDirtyResource(GetIDForResource(res)); + SAFE_RELEASE(res); + } - RTs[i] = UNWRAP(WrappedID3D11RenderTargetView, ppRenderTargetViews[i]); + RTs[i] = UNWRAP(WrappedID3D11RenderTargetView, ppRenderTargetViews[i]); + } } if(pDepthStencilView && m_State >= WRITING) @@ -4418,7 +4424,7 @@ HRESULT WrappedID3D11DeviceContext::FinishCommandList(BOOL RestoreDeferredContex m_CurrentPipelineState->Clear(); VerifyState(); - *ppCommandList = wrapped; + if (ppCommandList) *ppCommandList = wrapped; return hr; }