From 77f1a6fc86524e9f096b599b097ec4dda725a297 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Fri, 26 Mar 2021 16:55:17 -0700 Subject: [PATCH] Fixed /analyze warnings --- DirectXTex/DirectXTexConvert.cpp | 45 ++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/DirectXTex/DirectXTexConvert.cpp b/DirectXTex/DirectXTexConvert.cpp index b8cb245..2e49bf9 100644 --- a/DirectXTex/DirectXTexConvert.cpp +++ b/DirectXTex/DirectXTexConvert.cpp @@ -1611,15 +1611,23 @@ bool DirectX::_StoreScanline( size_t count, float threshold) noexcept { - assert(pDestination && size > 0); - assert(pSource && count > 0 && ((reinterpret_cast(pSource) & 0xF) == 0)); + assert(pDestination != nullptr); assert(IsValid(format) && !IsTypeless(format) && !IsCompressed(format) && !IsPlanar(format) && !IsPalettized(format)); + if (!size || !count) + return false; + const XMVECTOR* __restrict sPtr = pSource; if (!sPtr) return false; - const XMVECTOR* ePtr = pSource + count; + assert((reinterpret_cast(pSource) & 0xF) == 0); + + const XMVECTOR* ePtr = sPtr + count; + +#ifdef _PREFAST_ + *reinterpret_cast(pDestination) = 0; +#endif switch (static_cast(format)) { @@ -2735,9 +2743,10 @@ bool DirectX::_StoreScanlineLinear( TEX_FILTER_FLAGS flags, float threshold) noexcept { - assert(pDestination && size > 0); - assert(pSource && count > 0 && ((reinterpret_cast(pSource) & 0xF) == 0)); - assert(IsValid(format) && !IsTypeless(format) && !IsCompressed(format) && !IsPlanar(format) && !IsPalettized(format)); + if (!pSource || !count) + return false; + + assert((reinterpret_cast(pSource) & 0xF) == 0); switch (format) { @@ -2810,10 +2819,6 @@ bool DirectX::_LoadScanlineLinear( DXGI_FORMAT format, TEX_FILTER_FLAGS flags) noexcept { - assert(pDestination && count > 0 && ((reinterpret_cast(pDestination) & 0xF) == 0)); - assert(pSource && size > 0); - assert(IsValid(format) && !IsTypeless(format, false) && !IsCompressed(format) && !IsPlanar(format) && !IsPalettized(format)); - switch (format) { case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: @@ -3909,10 +3914,18 @@ bool DirectX::_StoreScanlineDither( size_t z, XMVECTOR* pDiffusionErrors) noexcept { - assert(pDestination && size > 0); - assert(pSource && count > 0 && ((reinterpret_cast(pSource) & 0xF) == 0)); + assert(pDestination != nullptr); assert(IsValid(format) && !IsTypeless(format) && !IsCompressed(format) && !IsPlanar(format) && !IsPalettized(format)); + if (!size || !count) + return false; + + const XMVECTOR* __restrict sPtr = pSource; + if (!sPtr) + return false; + + assert((reinterpret_cast(pSource) & 0xF) == 0); + XMVECTOR ordered[4]; if (pDiffusionErrors) { @@ -3945,12 +3958,12 @@ bool DirectX::_StoreScanlineDither( ordered[3] = XMVectorSplatW(dither); } - const XMVECTOR* __restrict sPtr = pSource; - if (!sPtr) - return false; - const void* ePtr = static_cast(pDestination) + size; +#ifdef _PREFAST_ + *reinterpret_cast(pDestination) = 0; +#endif + XMVECTOR vError = XMVectorZero(); switch (static_cast(format))