From 3fa722657914ffee6f19f4cbdcadb790daa45dad Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Wed, 26 Oct 2016 15:10:18 -0700 Subject: [PATCH] Code review feedback --- DirectXMesh/DirectXMeshOptimize.cpp | 10 +++++++++- DirectXMesh/DirectXMeshVBReader.cpp | 7 ++++++- DirectXMesh/DirectXMeshVBWriter.cpp | 7 ++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/DirectXMesh/DirectXMeshOptimize.cpp b/DirectXMesh/DirectXMeshOptimize.cpp index 84a0d568..61030c59 100644 --- a/DirectXMesh/DirectXMeshOptimize.cpp +++ b/DirectXMesh/DirectXMeshOptimize.cpp @@ -17,6 +17,8 @@ using namespace DirectX; +#pragma warning(disable : 4351) + namespace { @@ -26,6 +28,7 @@ class mesh_status { public: mesh_status() : + mUnprocessed{}, mFaceOffset(0), mFaceCount(0), mMaxSubset(0), @@ -327,6 +330,8 @@ class mesh_status { assert( face < mTotalFaces ); assert( n < 3 ); + _Analysis_assume_( face < mTotalFaces ); + _Analysis_assume_( n < 3 ); return mPhysicalNeighbors[ face ].neighbors[ n ]; } @@ -760,7 +765,7 @@ HRESULT _VertexCacheStripReorder( _In_reads_(nFaces*3) const index_t* indices, _ //------------------------------------------------------------------------------------- template -HRESULT _OptimizeVertices( const index_t* indices, size_t nFaces, size_t nVerts, uint32_t* vertexRemap ) +HRESULT _OptimizeVertices( _In_reads_(nFaces*3) const index_t* indices, size_t nFaces, size_t nVerts, _Out_writes_(nVerts) uint32_t* vertexRemap ) { if ( !indices || !nFaces || !nVerts || !vertexRemap ) return E_INVALIDARG; @@ -802,6 +807,9 @@ HRESULT _OptimizeVertices( const index_t* indices, size_t nFaces, size_t nVerts, uint32_t vertindex = tempRemap[ j ]; if ( vertindex != UNUSED32 ) { + if ( vertindex >= nVerts ) + return E_UNEXPECTED; + vertexRemap[ vertindex ] = j; } } diff --git a/DirectXMesh/DirectXMeshVBReader.cpp b/DirectXMesh/DirectXMeshVBReader.cpp index dd976a5d..804416bf 100644 --- a/DirectXMesh/DirectXMeshVBReader.cpp +++ b/DirectXMesh/DirectXMeshVBReader.cpp @@ -23,7 +23,12 @@ namespace DirectX class VBReader::Impl { public: - Impl() : mTempSize(0) {} + Impl() : + mStrides{}, + mBuffers{}, + mVerts{}, + mDefaultStrides{}, + mTempSize(0) {} HRESULT Initialize( _In_reads_(nDecl) const D3D11_INPUT_ELEMENT_DESC* vbDecl, size_t nDecl ); HRESULT AddStream( _In_reads_bytes_(stride*nVerts) const void* vb, size_t nVerts, size_t inputSlot, size_t stride ); diff --git a/DirectXMesh/DirectXMeshVBWriter.cpp b/DirectXMesh/DirectXMeshVBWriter.cpp index f00b82a3..71a5dfc3 100644 --- a/DirectXMesh/DirectXMeshVBWriter.cpp +++ b/DirectXMesh/DirectXMeshVBWriter.cpp @@ -23,7 +23,12 @@ namespace DirectX class VBWriter::Impl { public: - Impl() : mTempSize(0) {} + Impl() : + mStrides{}, + mBuffers{}, + mVerts{}, + mDefaultStrides{}, + mTempSize(0) {} HRESULT Initialize( _In_reads_(nDecl) const D3D11_INPUT_ELEMENT_DESC* vbDecl, size_t nDecl ); HRESULT AddStream( _Out_writes_bytes_(stride*nVerts) void* vb, size_t nVerts, size_t inputSlot, size_t stride );