Skip to content

Commit 8480f4f

Browse files
committed
Additional C++ Core Checker cleanup
1 parent 4724707 commit 8480f4f

15 files changed

+233
-236
lines changed

DirectXTex/BC.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,10 @@ template <bool bRange> void OptimizeAlpha(float *pX, float *pY, const float *pPo
220220

221221
for (size_t iIteration = 0; iIteration < 8; iIteration++)
222222
{
223-
float fScale;
224-
225223
if ((fY - fX) < (1.0f / 256.0f))
226224
break;
227225

228-
fScale = fSteps / (fY - fX);
226+
float fScale = fSteps / (fY - fX);
229227

230228
// Calculate new steps
231229
float pSteps[8];

DirectXTex/BCDirectCompute.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ HRESULT GPUCompressBC::Compress(const Image& srcImage, const Image& destImage)
589589
HRESULT hr = pContext->Map(m_outputCPU.Get(), 0, D3D11_MAP_READ, 0, &mapped);
590590
if (SUCCEEDED(hr))
591591
{
592-
const uint8_t *pSrc = reinterpret_cast<const uint8_t *>(mapped.pData);
592+
auto pSrc = static_cast<const uint8_t *>(mapped.pData);
593593
uint8_t *pDest = destImage.pixels;
594594

595595
size_t pitch = xblocks * sizeof(BufferBC6HBC7);

DirectXTex/DirectXTexCompressGPU.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ namespace
5858
return E_POINTER;
5959
}
6060

61-
ScopedAlignedArrayXMVECTOR scanline(reinterpret_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR) * srcImage.width), 16)));
61+
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR) * srcImage.width), 16)));
6262
if (!scanline)
6363
{
6464
image.Release();
@@ -163,7 +163,7 @@ namespace
163163
{
164164
// Convert format and then use as the source image
165165
ScratchImage image;
166-
HRESULT hr;
166+
HRESULT hr = E_UNEXPECTED;
167167

168168
DWORD srgb = GetSRGBFlags(compress);
169169

@@ -182,7 +182,6 @@ namespace
182182
break;
183183

184184
default:
185-
hr = E_UNEXPECTED;
186185
break;
187186
}
188187

DirectXTex/DirectXTexConvert.cpp

+117-117
Large diffs are not rendered by default.

DirectXTex/DirectXTexD3D11.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ namespace
8181
if (FAILED(hr))
8282
return hr;
8383

84-
auto pslice = reinterpret_cast<const uint8_t*>(mapped.pData);
84+
auto pslice = static_cast<const uint8_t*>(mapped.pData);
8585
if (!pslice)
8686
{
8787
pContext->Unmap(pSource, dindex);
@@ -169,7 +169,7 @@ namespace
169169
return E_UNEXPECTED;
170170
}
171171

172-
auto sptr = reinterpret_cast<const uint8_t*>(mapped.pData);
172+
auto sptr = static_cast<const uint8_t*>(mapped.pData);
173173
uint8_t* dptr = img->pixels;
174174
for (size_t h = 0; h < lines; ++h)
175175
{
@@ -537,7 +537,7 @@ HRESULT DirectX::CreateTextureEx(
537537
}
538538

539539
// Create texture using static initialization data
540-
HRESULT hr = E_FAIL;
540+
HRESULT hr = E_UNEXPECTED;
541541

542542
DXGI_FORMAT tformat = (forceSRGB) ? MakeSRGB(metadata.format) : metadata.format;
543543

@@ -734,7 +734,7 @@ HRESULT DirectX::CaptureTexture(
734734
D3D11_RESOURCE_DIMENSION resType = D3D11_RESOURCE_DIMENSION_UNKNOWN;
735735
pSource->GetType(&resType);
736736

737-
HRESULT hr;
737+
HRESULT hr = E_UNEXPECTED;
738738

739739
switch (resType)
740740
{

DirectXTex/DirectXTexDDS.cpp

+36-36
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ namespace
281281
}
282282

283283
// DDS files always start with the same magic number ("DDS ")
284-
uint32_t dwMagicNumber = *reinterpret_cast<const uint32_t*>(pSource);
284+
auto dwMagicNumber = *static_cast<const uint32_t*>(pSource);
285285
if (dwMagicNumber != DDS_MAGIC)
286286
{
287287
return E_FAIL;
@@ -618,9 +618,9 @@ HRESULT DirectX::_EncodeDDSHeader(
618618
if (maxsize < required)
619619
return E_NOT_SUFFICIENT_BUFFER;
620620

621-
*reinterpret_cast<uint32_t*>(pDestination) = DDS_MAGIC;
621+
*static_cast<uint32_t*>(pDestination) = DDS_MAGIC;
622622

623-
auto header = reinterpret_cast<DDS_HEADER*>(reinterpret_cast<uint8_t*>(pDestination) + sizeof(uint32_t));
623+
auto header = reinterpret_cast<DDS_HEADER*>(static_cast<uint8_t*>(pDestination) + sizeof(uint32_t));
624624
assert(header);
625625

626626
memset(header, 0, sizeof(DDS_HEADER));
@@ -827,8 +827,8 @@ namespace
827827
// D3DFMT_R8G8B8 -> DXGI_FORMAT_R8G8B8A8_UNORM
828828
if (inSize >= 3 && outSize >= 4)
829829
{
830-
const uint8_t * __restrict sPtr = reinterpret_cast<const uint8_t*>(pSource);
831-
uint32_t * __restrict dPtr = reinterpret_cast<uint32_t*>(pDestination);
830+
const uint8_t * __restrict sPtr = static_cast<const uint8_t*>(pSource);
831+
uint32_t * __restrict dPtr = static_cast<uint32_t*>(pDestination);
832832

833833
for (size_t ocount = 0, icount = 0; ((icount < (inSize - 2)) && (ocount < (outSize - 3))); icount += 3, ocount += 4)
834834
{
@@ -851,8 +851,8 @@ namespace
851851
// D3DFMT_R3G3B2 -> DXGI_FORMAT_R8G8B8A8_UNORM
852852
if (inSize >= 1 && outSize >= 4)
853853
{
854-
const uint8_t* __restrict sPtr = reinterpret_cast<const uint8_t*>(pSource);
855-
uint32_t * __restrict dPtr = reinterpret_cast<uint32_t*>(pDestination);
854+
const uint8_t* __restrict sPtr = static_cast<const uint8_t*>(pSource);
855+
uint32_t * __restrict dPtr = static_cast<uint32_t*>(pDestination);
856856

857857
for (size_t ocount = 0, icount = 0; ((icount < inSize) && (ocount < (outSize - 3))); ++icount, ocount += 4)
858858
{
@@ -872,8 +872,8 @@ namespace
872872
// D3DFMT_R3G3B2 -> DXGI_FORMAT_B5G6R5_UNORM
873873
if (inSize >= 1 && outSize >= 2)
874874
{
875-
const uint8_t* __restrict sPtr = reinterpret_cast<const uint8_t*>(pSource);
876-
uint16_t * __restrict dPtr = reinterpret_cast<uint16_t*>(pDestination);
875+
const uint8_t* __restrict sPtr = static_cast<const uint8_t*>(pSource);
876+
uint16_t * __restrict dPtr = static_cast<uint16_t*>(pDestination);
877877

878878
for (size_t ocount = 0, icount = 0; ((icount < inSize) && (ocount < (outSize - 1))); ++icount, ocount += 2)
879879
{
@@ -901,8 +901,8 @@ namespace
901901
// D3DFMT_A8R3G3B2 -> DXGI_FORMAT_R8G8B8A8_UNORM
902902
if (inSize >= 2 && outSize >= 4)
903903
{
904-
const uint16_t* __restrict sPtr = reinterpret_cast<const uint16_t*>(pSource);
905-
uint32_t * __restrict dPtr = reinterpret_cast<uint32_t*>(pDestination);
904+
const uint16_t* __restrict sPtr = static_cast<const uint16_t*>(pSource);
905+
uint32_t * __restrict dPtr = static_cast<uint32_t*>(pDestination);
906906

907907
for (size_t ocount = 0, icount = 0; ((icount < (inSize - 1)) && (ocount < (outSize - 3))); icount += 2, ocount += 4)
908908
{
@@ -926,8 +926,8 @@ namespace
926926
// D3DFMT_P8 -> DXGI_FORMAT_R8G8B8A8_UNORM
927927
if (inSize >= 1 && outSize >= 4)
928928
{
929-
const uint8_t* __restrict sPtr = reinterpret_cast<const uint8_t*>(pSource);
930-
uint32_t * __restrict dPtr = reinterpret_cast<uint32_t*>(pDestination);
929+
const uint8_t* __restrict sPtr = static_cast<const uint8_t*>(pSource);
930+
uint32_t * __restrict dPtr = static_cast<uint32_t*>(pDestination);
931931

932932
for (size_t ocount = 0, icount = 0; ((icount < inSize) && (ocount < (outSize - 3))); ++icount, ocount += 4)
933933
{
@@ -946,8 +946,8 @@ namespace
946946
// D3DFMT_A8P8 -> DXGI_FORMAT_R8G8B8A8_UNORM
947947
if (inSize >= 2 && outSize >= 4)
948948
{
949-
const uint16_t* __restrict sPtr = reinterpret_cast<const uint16_t*>(pSource);
950-
uint32_t * __restrict dPtr = reinterpret_cast<uint32_t*>(pDestination);
949+
const uint16_t* __restrict sPtr = static_cast<const uint16_t*>(pSource);
950+
uint32_t * __restrict dPtr = static_cast<uint32_t*>(pDestination);
951951

952952
for (size_t ocount = 0, icount = 0; ((icount < (inSize - 1)) && (ocount < (outSize - 3))); icount += 2, ocount += 4)
953953
{
@@ -969,8 +969,8 @@ namespace
969969
// D3DFMT_A4L4 -> DXGI_FORMAT_B4G4R4A4_UNORM
970970
if (inSize >= 1 && outSize >= 2)
971971
{
972-
const uint8_t * __restrict sPtr = reinterpret_cast<const uint8_t*>(pSource);
973-
uint16_t * __restrict dPtr = reinterpret_cast<uint16_t*>(pDestination);
972+
const uint8_t * __restrict sPtr = static_cast<const uint8_t*>(pSource);
973+
uint16_t * __restrict dPtr = static_cast<uint16_t*>(pDestination);
974974

975975
for (size_t ocount = 0, icount = 0; ((icount < inSize) && (ocount < (outSize - 1))); ++icount, ocount += 2)
976976
{
@@ -989,8 +989,8 @@ namespace
989989
// D3DFMT_A4L4 -> DXGI_FORMAT_R8G8B8A8_UNORM
990990
if (inSize >= 1 && outSize >= 4)
991991
{
992-
const uint8_t * __restrict sPtr = reinterpret_cast<const uint8_t*>(pSource);
993-
uint32_t * __restrict dPtr = reinterpret_cast<uint32_t*>(pDestination);
992+
const uint8_t * __restrict sPtr = static_cast<const uint8_t*>(pSource);
993+
uint32_t * __restrict dPtr = static_cast<uint32_t*>(pDestination);
994994

995995
for (size_t ocount = 0, icount = 0; ((icount < inSize) && (ocount < (outSize - 3))); ++icount, ocount += 4)
996996
{
@@ -1017,8 +1017,8 @@ namespace
10171017
// D3DFMT_A4R4G4B4 -> DXGI_FORMAT_R8G8B8A8_UNORM
10181018
if (inSize >= 2 && outSize >= 4)
10191019
{
1020-
const uint16_t * __restrict sPtr = reinterpret_cast<const uint16_t*>(pSource);
1021-
uint32_t * __restrict dPtr = reinterpret_cast<uint32_t*>(pDestination);
1020+
const uint16_t * __restrict sPtr = static_cast<const uint16_t*>(pSource);
1021+
uint32_t * __restrict dPtr = static_cast<uint32_t*>(pDestination);
10221022

10231023
for (size_t ocount = 0, icount = 0; ((icount < (inSize - 1)) && (ocount < (outSize - 3))); icount += 2, ocount += 4)
10241024
{
@@ -1042,8 +1042,8 @@ namespace
10421042
// D3DFMT_L8 -> DXGI_FORMAT_R8G8B8A8_UNORM
10431043
if (inSize >= 1 && outSize >= 4)
10441044
{
1045-
const uint8_t * __restrict sPtr = reinterpret_cast<const uint8_t*>(pSource);
1046-
uint32_t * __restrict dPtr = reinterpret_cast<uint32_t*>(pDestination);
1045+
const uint8_t * __restrict sPtr = static_cast<const uint8_t*>(pSource);
1046+
uint32_t * __restrict dPtr = static_cast<uint32_t*>(pDestination);
10471047

10481048
for (size_t ocount = 0, icount = 0; ((icount < inSize) && (ocount < (outSize - 3))); ++icount, ocount += 4)
10491049
{
@@ -1064,8 +1064,8 @@ namespace
10641064
// D3DFMT_L16 -> DXGI_FORMAT_R16G16B16A16_UNORM
10651065
if (inSize >= 2 && outSize >= 8)
10661066
{
1067-
const uint16_t* __restrict sPtr = reinterpret_cast<const uint16_t*>(pSource);
1068-
uint64_t * __restrict dPtr = reinterpret_cast<uint64_t*>(pDestination);
1067+
const uint16_t* __restrict sPtr = static_cast<const uint16_t*>(pSource);
1068+
uint64_t * __restrict dPtr = static_cast<uint64_t*>(pDestination);
10691069

10701070
for (size_t ocount = 0, icount = 0; ((icount < (inSize - 1)) && (ocount < (outSize - 7))); icount += 2, ocount += 8)
10711071
{
@@ -1088,8 +1088,8 @@ namespace
10881088
// D3DFMT_A8L8 -> DXGI_FORMAT_R8G8B8A8_UNORM
10891089
if (inSize >= 2 && outSize >= 4)
10901090
{
1091-
const uint16_t* __restrict sPtr = reinterpret_cast<const uint16_t*>(pSource);
1092-
uint32_t * __restrict dPtr = reinterpret_cast<uint32_t*>(pDestination);
1091+
const uint16_t* __restrict sPtr = static_cast<const uint16_t*>(pSource);
1092+
uint32_t * __restrict dPtr = static_cast<uint32_t*>(pDestination);
10931093

10941094
for (size_t ocount = 0, icount = 0; ((icount < (inSize - 1)) && (ocount < (outSize - 3))); icount += 2, ocount += 4)
10951095
{
@@ -1198,7 +1198,7 @@ namespace
11981198
size_t dpitch = images[index].rowPitch;
11991199
size_t spitch = timages[index].rowPitch;
12001200

1201-
const uint8_t *pSrc = const_cast<const uint8_t*>(timages[index].pixels);
1201+
const uint8_t *pSrc = timages[index].pixels;
12021202
if (!pSrc)
12031203
return E_POINTER;
12041204

@@ -1300,7 +1300,7 @@ namespace
13001300
size_t dpitch = images[index].rowPitch;
13011301
size_t spitch = timages[index].rowPitch;
13021302

1303-
const uint8_t *pSrc = const_cast<const uint8_t*>(timages[index].pixels);
1303+
const uint8_t *pSrc = timages[index].pixels;
13041304
if (!pSrc)
13051305
return E_POINTER;
13061306

@@ -1492,7 +1492,7 @@ HRESULT DirectX::GetMetadataFromDDSFile(
14921492

14931493
// Read the header in (including extended header if present)
14941494
const size_t MAX_HEADER_SIZE = sizeof(uint32_t) + sizeof(DDS_HEADER) + sizeof(DDS_HEADER_DXT10);
1495-
uint8_t header[MAX_HEADER_SIZE];
1495+
uint8_t header[MAX_HEADER_SIZE] = {};
14961496

14971497
DWORD bytesRead = 0;
14981498
if (!ReadFile(hFile.get(), header, MAX_HEADER_SIZE, &bytesRead, nullptr))
@@ -1536,7 +1536,7 @@ HRESULT DirectX::LoadFromDDSMemory(
15361536
const uint32_t *pal8 = nullptr;
15371537
if (convFlags & CONV_FLAGS_PAL8)
15381538
{
1539-
pal8 = reinterpret_cast<const uint32_t*>(reinterpret_cast<const uint8_t*>(pSource) + offset);
1539+
pal8 = reinterpret_cast<const uint32_t*>(static_cast<const uint8_t*>(pSource) + offset);
15401540
assert(pal8);
15411541
offset += (256 * sizeof(uint32_t));
15421542
if (size < offset)
@@ -1557,7 +1557,7 @@ HRESULT DirectX::LoadFromDDSMemory(
15571557
cflags |= CP_FLAGS_BAD_DXTN_TAILS;
15581558
}
15591559

1560-
auto pPixels = reinterpret_cast<const void*>(reinterpret_cast<const uint8_t*>(pSource) + offset);
1560+
const void* pPixels = static_cast<const uint8_t*>(pSource) + offset;
15611561
assert(pPixels);
15621562
hr = CopyImage(pPixels,
15631563
size - offset,
@@ -1626,7 +1626,7 @@ HRESULT DirectX::LoadFromDDSFile(
16261626

16271627
// Read the header in (including extended header if present)
16281628
const size_t MAX_HEADER_SIZE = sizeof(uint32_t) + sizeof(DDS_HEADER) + sizeof(DDS_HEADER_DXT10);
1629-
uint8_t header[MAX_HEADER_SIZE];
1629+
uint8_t header[MAX_HEADER_SIZE] = {};
16301630

16311631
DWORD bytesRead = 0;
16321632
if (!ReadFile(hFile.get(), header, MAX_HEADER_SIZE, &bytesRead, nullptr))
@@ -1813,7 +1813,7 @@ HRESULT DirectX::SaveToDDSMemory(
18131813
if (FAILED(hr))
18141814
return hr;
18151815

1816-
auto pDestination = reinterpret_cast<uint8_t*>(blob.GetBufferPointer());
1816+
auto pDestination = static_cast<uint8_t*>(blob.GetBufferPointer());
18171817
assert(pDestination);
18181818

18191819
hr = _EncodeDDSHeader(metadata, flags, pDestination, blob.GetBufferSize(), required);
@@ -1868,7 +1868,7 @@ HRESULT DirectX::SaveToDDSMemory(
18681868
size_t rowPitch = images[index].rowPitch;
18691869

18701870
const uint8_t * __restrict sPtr = images[index].pixels;
1871-
uint8_t * __restrict dPtr = reinterpret_cast<uint8_t*>(pDestination);
1871+
uint8_t * __restrict dPtr = pDestination;
18721872

18731873
size_t lines = ComputeScanlines(metadata.format, images[index].height);
18741874
size_t csize = std::min<size_t>(rowPitch, ddsRowPitch);
@@ -1937,7 +1937,7 @@ HRESULT DirectX::SaveToDDSMemory(
19371937
size_t rowPitch = images[index].rowPitch;
19381938

19391939
const uint8_t * __restrict sPtr = images[index].pixels;
1940-
uint8_t * __restrict dPtr = reinterpret_cast<uint8_t*>(pDestination);
1940+
uint8_t * __restrict dPtr = pDestination;
19411941

19421942
size_t lines = ComputeScanlines(metadata.format, images[index].height);
19431943
size_t csize = std::min<size_t>(rowPitch, ddsRowPitch);

DirectXTex/DirectXTexHDR.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ namespace
102102

103103
// Process first part of header
104104
bool formatFound = false;
105-
const char* info = reinterpret_cast<const char*>(pSource);
105+
auto info = static_cast<const char*>(pSource);
106106
while (size > 0)
107107
{
108108
if (*info == '\n')
@@ -275,7 +275,7 @@ namespace
275275
return E_FAIL;
276276
}
277277

278-
offset = info - reinterpret_cast<const char*>(pSource);
278+
offset = info - static_cast<const char*>(pSource);
279279

280280
metadata.width = width;
281281
metadata.height = height;
@@ -569,7 +569,7 @@ HRESULT DirectX::GetMetadataFromHDRFile(const wchar_t* szFile, TexMetadata& meta
569569
}
570570

571571
// Read the first part of the file to find the header
572-
uint8_t header[8192];
572+
uint8_t header[8192] = {};
573573
DWORD bytesRead = 0;
574574
if (!ReadFile(hFile.get(), header, std::min<DWORD>(sizeof(header), fileInfo.EndOfFile.LowPart), &bytesRead, nullptr))
575575
{
@@ -612,7 +612,7 @@ HRESULT DirectX::LoadFromHDRMemory(const void* pSource, size_t size, TexMetadata
612612
return hr;
613613

614614
// Copy pixels
615-
auto sourcePtr = reinterpret_cast<const uint8_t*>(pSource) + offset;
615+
auto sourcePtr = static_cast<const uint8_t*>(pSource) + offset;
616616

617617
size_t pixelLen = remaining;
618618

@@ -908,7 +908,7 @@ HRESULT DirectX::SaveToHDRMemory(const Image& image, Blob& blob)
908908
return hr;
909909

910910
// Copy header
911-
auto dPtr = reinterpret_cast<uint8_t*>(blob.GetBufferPointer());
911+
auto dPtr = static_cast<uint8_t*>(blob.GetBufferPointer());
912912
assert(dPtr != 0);
913913
memcpy_s(dPtr, blob.GetBufferSize(), header, headerLen);
914914
dPtr += headerLen;
@@ -933,7 +933,7 @@ HRESULT DirectX::SaveToHDRMemory(const Image& image, Blob& blob)
933933
auto rgbe = temp.get();
934934
auto enc = temp.get() + rowPitch;
935935

936-
auto sPtr = reinterpret_cast<const uint8_t*>(image.pixels);
936+
const uint8_t* sPtr = image.pixels;
937937
for (size_t scan = 0; scan < image.height; ++scan)
938938
{
939939
FloatToRGBE(rgbe, reinterpret_cast<const float*>(sPtr), image.width, fpp);
@@ -953,7 +953,7 @@ HRESULT DirectX::SaveToHDRMemory(const Image& image, Blob& blob)
953953
}
954954
#endif
955955

956-
hr = blob.Trim(dPtr - reinterpret_cast<uint8_t*>(blob.GetBufferPointer()));
956+
hr = blob.Trim(dPtr - static_cast<uint8_t*>(blob.GetBufferPointer()));
957957
if (FAILED(hr))
958958
{
959959
blob.Release();
@@ -1079,7 +1079,7 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile)
10791079
#else
10801080
auto enc = temp.get() + rowPitch;
10811081

1082-
auto sPtr = reinterpret_cast<const uint8_t*>(image.pixels);
1082+
const uint8_t* sPtr = image.pixels;
10831083
for (size_t scan = 0; scan < image.height; ++scan)
10841084
{
10851085
FloatToRGBE(rgbe, reinterpret_cast<const float*>(sPtr), image.width, fpp);

0 commit comments

Comments
 (0)