refactor: only use sizeof with parenthesis

This commit is contained in:
Jan 2024-03-24 19:56:06 +01:00
parent 4f0ee35740
commit 1b13f1f1b4
No known key found for this signature in database
GPG Key ID: 44B581F78FF5C57C
16 changed files with 33 additions and 33 deletions

View File

@ -46,8 +46,8 @@ class IPak::Impl : public ObjContainerReferenceable
for (unsigned itemIndex = 0; itemIndex < m_index_section->itemCount; itemIndex++)
{
m_stream->read(reinterpret_cast<char*>(&indexEntry), sizeof indexEntry);
if (m_stream->gcount() != sizeof indexEntry)
m_stream->read(reinterpret_cast<char*>(&indexEntry), sizeof(indexEntry));
if (m_stream->gcount() != sizeof(indexEntry))
{
printf("Unexpected eof when trying to load index entry %u.\n", itemIndex);
return false;
@ -99,7 +99,7 @@ class IPak::Impl : public ObjContainerReferenceable
IPakHeader header{};
m_stream->read(reinterpret_cast<char*>(&header), sizeof(header));
if (m_stream->gcount() != sizeof header)
if (m_stream->gcount() != sizeof(header))
{
printf("Unexpected eof when trying to load header.\n");
return false;

View File

@ -126,7 +126,7 @@ protected:
while (skipAmount > 0)
{
char temp[1024];
const auto toRead = skipAmount > sizeof temp ? sizeof temp : static_cast<size_t>(skipAmount);
const auto toRead = skipAmount > sizeof(temp) ? sizeof(temp) : static_cast<size_t>(skipAmount);
unzReadCurrentFile(m_container, temp, toRead);
skipAmount -= toRead;
}
@ -216,7 +216,7 @@ public:
{
unz_file_info64 info;
char fileNameBuffer[256];
unzGetCurrentFileInfo64(m_unz_file, &info, fileNameBuffer, sizeof fileNameBuffer, nullptr, 0, nullptr, 0);
unzGetCurrentFileInfo64(m_unz_file, &info, fileNameBuffer, sizeof(fileNameBuffer), nullptr, 0, nullptr, 0);
std::string fileName(fileNameBuffer);
std::filesystem::path path(fileName);

View File

@ -44,7 +44,7 @@ void AssetDumperRawFile::DumpAsset(AssetDumpingContext& context, XAssetInfo<RawF
while (zs.avail_in > 0)
{
zs.next_out = buffer;
zs.avail_out = sizeof buffer;
zs.avail_out = sizeof(buffer);
ret = inflate(&zs, Z_SYNC_FLUSH);
if (ret < 0)
@ -54,7 +54,7 @@ void AssetDumperRawFile::DumpAsset(AssetDumpingContext& context, XAssetInfo<RawF
return;
}
stream.write(reinterpret_cast<char*>(buffer), sizeof buffer - zs.avail_out);
stream.write(reinterpret_cast<char*>(buffer), sizeof(buffer) - zs.avail_out);
}
inflateEnd(&zs);

View File

@ -44,7 +44,7 @@ void AssetDumperRawFile::DumpAsset(AssetDumpingContext& context, XAssetInfo<RawF
while (zs.avail_in > 0)
{
zs.next_out = buffer;
zs.avail_out = sizeof buffer;
zs.avail_out = sizeof(buffer);
ret = inflate(&zs, Z_SYNC_FLUSH);
if (ret < 0)
@ -54,7 +54,7 @@ void AssetDumperRawFile::DumpAsset(AssetDumpingContext& context, XAssetInfo<RawF
return;
}
stream.write(reinterpret_cast<char*>(buffer), sizeof buffer - zs.avail_out);
stream.write(reinterpret_cast<char*>(buffer), sizeof(buffer) - zs.avail_out);
}
inflateEnd(&zs);

View File

@ -59,7 +59,7 @@ void AssetDumperRawFile::DumpGsc(AssetDumpingContext& context, XAssetInfo<RawFil
while (zs.avail_in > 0)
{
zs.next_out = buffer;
zs.avail_out = sizeof buffer;
zs.avail_out = sizeof(buffer);
ret = inflate(&zs, Z_SYNC_FLUSH);
if (ret < 0)
@ -69,7 +69,7 @@ void AssetDumperRawFile::DumpGsc(AssetDumpingContext& context, XAssetInfo<RawFil
return;
}
const auto inflateOutSize = sizeof buffer - zs.avail_out;
const auto inflateOutSize = sizeof(buffer) - zs.avail_out;
if (writtenSize + inflateOutSize >= outLen)
{

View File

@ -55,7 +55,7 @@ void AssetDumperRawFile::DumpAnimtree(AssetDumpingContext& context, XAssetInfo<R
while (zs.avail_in > 0)
{
zs.next_out = buffer;
zs.avail_out = sizeof buffer;
zs.avail_out = sizeof(buffer);
ret = inflate(&zs, Z_SYNC_FLUSH);
if (ret < 0)
@ -65,7 +65,7 @@ void AssetDumperRawFile::DumpAnimtree(AssetDumpingContext& context, XAssetInfo<R
return;
}
const auto inflateOutSize = sizeof buffer - zs.avail_out;
const auto inflateOutSize = sizeof(buffer) - zs.avail_out;
stream.write(reinterpret_cast<char*>(buffer), inflateOutSize);
}

View File

@ -95,7 +95,7 @@ class DdsWriterInternal
void PopulateDdsHeader(DDS_HEADER& header)
{
header.dwSize = sizeof header;
header.dwSize = sizeof(header);
header.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
if (m_texture->HasMipMaps())
@ -201,14 +201,14 @@ public:
constexpr auto magic = MakeFourCc('D', 'D', 'S', ' ');
m_stream.write(reinterpret_cast<const char*>(&magic), sizeof magic);
m_stream.write(reinterpret_cast<const char*>(&header), sizeof header);
m_stream.write(reinterpret_cast<const char*>(&magic), sizeof(magic));
m_stream.write(reinterpret_cast<const char*>(&header), sizeof(header));
if (m_use_dx10_extension)
{
DDS_HEADER_DXT10 dxt10{};
PopulateDxt10Header(dxt10);
m_stream.write(reinterpret_cast<const char*>(&dxt10), sizeof dxt10);
m_stream.write(reinterpret_cast<const char*>(&dxt10), sizeof(dxt10));
}
const auto mipCount = m_texture->HasMipMaps() ? m_texture->GetMipMapCount() : 1;

View File

@ -146,7 +146,7 @@ void ContentLoader::Load(Zone* zone, IZoneInputStream* stream)
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
XAssetList assetList{};
m_stream->LoadDataRaw(&assetList, sizeof assetList);
m_stream->LoadDataRaw(&assetList, sizeof(assetList));
varScriptStringList = &assetList.stringList;
LoadScriptStringList(false);

View File

@ -166,7 +166,7 @@ void ContentLoader::Load(Zone* zone, IZoneInputStream* stream)
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
XAssetList assetList{};
m_stream->LoadDataRaw(&assetList, sizeof assetList);
m_stream->LoadDataRaw(&assetList, sizeof(assetList));
varScriptStringList = &assetList.stringList;
LoadScriptStringList(false);

View File

@ -130,11 +130,11 @@ class ZoneLoaderFactory::Impl
zoneLoader->AddLoadingStep(std::make_unique<StepVerifyMagic>(ZoneConstants::MAGIC_AUTH_HEADER));
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
auto subHeaderHash = std::make_unique<StepLoadHash>(sizeof DB_AuthHash::bytes, 1);
auto subHeaderHash = std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), 1);
auto* subHeaderHashPtr = subHeaderHash.get();
zoneLoader->AddLoadingStep(std::move(subHeaderHash));
auto subHeaderHashSignature = std::make_unique<StepLoadSignature>(sizeof DB_AuthSignature::bytes);
auto subHeaderHashSignature = std::make_unique<StepLoadSignature>(sizeof(DB_AuthSignature::bytes));
auto* subHeaderHashSignaturePtr = subHeaderHashSignature.get();
zoneLoader->AddLoadingStep(std::move(subHeaderHashSignature));
@ -147,7 +147,7 @@ class ZoneLoaderFactory::Impl
zoneLoader->AddLoadingStep(std::make_unique<StepVerifyFileName>(fileName, sizeof(DB_AuthSubHeader::fastfileName)));
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
auto masterBlockHashes = std::make_unique<StepLoadHash>(sizeof DB_AuthHash::bytes, std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>);
auto masterBlockHashes = std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>);
auto* masterBlockHashesPtr = masterBlockHashes.get();
zoneLoader->AddLoadingStep(std::move(masterBlockHashes));

View File

@ -175,7 +175,7 @@ void ContentLoader::Load(Zone* zone, IZoneInputStream* stream)
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
XAssetList assetList{};
m_stream->LoadDataRaw(&assetList, sizeof assetList);
m_stream->LoadDataRaw(&assetList, sizeof(assetList));
varScriptStringList = &assetList.stringList;
LoadScriptStringList(false);

View File

@ -114,11 +114,11 @@ class ZoneLoaderFactory::Impl
zoneLoader->AddLoadingStep(std::make_unique<StepVerifyMagic>(ZoneConstants::MAGIC_AUTH_HEADER));
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
auto subHeaderHash = std::make_unique<StepLoadHash>(sizeof DB_AuthHash::bytes, 1);
auto subHeaderHash = std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), 1);
auto* subHeaderHashPtr = subHeaderHash.get();
zoneLoader->AddLoadingStep(std::move(subHeaderHash));
auto subHeaderHashSignature = std::make_unique<StepLoadSignature>(sizeof DB_AuthSignature::bytes);
auto subHeaderHashSignature = std::make_unique<StepLoadSignature>(sizeof(DB_AuthSignature::bytes));
auto* subHeaderHashSignaturePtr = subHeaderHashSignature.get();
zoneLoader->AddLoadingStep(std::move(subHeaderHashSignature));
@ -131,7 +131,7 @@ class ZoneLoaderFactory::Impl
zoneLoader->AddLoadingStep(std::make_unique<StepVerifyFileName>(fileName, sizeof(DB_AuthSubHeader::fastfileName)));
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
auto masterBlockHashes = std::make_unique<StepLoadHash>(sizeof DB_AuthHash::bytes, std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>);
auto masterBlockHashes = std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>);
auto* masterBlockHashesPtr = masterBlockHashes.get();
zoneLoader->AddLoadingStep(std::move(masterBlockHashes));

View File

@ -159,7 +159,7 @@ void ContentLoader::Load(Zone* zone, IZoneInputStream* stream)
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
XAssetList assetList{};
m_stream->LoadDataRaw(&assetList, sizeof assetList);
m_stream->LoadDataRaw(&assetList, sizeof(assetList));
varScriptStringList = &assetList.stringList;
LoadScriptStringList(false);

View File

@ -188,7 +188,7 @@ void ContentLoader::Load(Zone* zone, IZoneInputStream* stream)
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
XAssetList assetList{};
m_stream->LoadDataRaw(&assetList, sizeof assetList);
m_stream->LoadDataRaw(&assetList, sizeof(assetList));
varScriptStringList = &assetList.stringList;
LoadScriptStringList(false);

View File

@ -150,16 +150,16 @@ class ProcessorXChunks::ProcessorXChunksImpl
xchunk_size_t chunkSize;
if (m_vanilla_buffer_size > 0)
{
if (m_vanilla_buffer_offset + sizeof chunkSize > m_vanilla_buffer_size)
if (m_vanilla_buffer_offset + sizeof(chunkSize) > m_vanilla_buffer_size)
{
m_base->m_base_stream->Load(&chunkSize, m_vanilla_buffer_size - m_vanilla_buffer_offset);
m_vanilla_buffer_offset = 0;
}
m_vanilla_buffer_offset = (m_vanilla_buffer_offset + sizeof chunkSize) % m_vanilla_buffer_size;
m_vanilla_buffer_offset = (m_vanilla_buffer_offset + sizeof(chunkSize)) % m_vanilla_buffer_size;
}
const size_t readSize = m_base->m_base_stream->Load(&chunkSize, sizeof chunkSize);
const size_t readSize = m_base->m_base_stream->Load(&chunkSize, sizeof(chunkSize));
if (readSize == 0)
{

View File

@ -33,8 +33,8 @@ std::unique_ptr<Zone> ZoneLoading::LoadZone(const std::string& path)
}
ZoneHeader header{};
file.read(reinterpret_cast<char*>(&header), sizeof header);
if (file.gcount() != sizeof header)
file.read(reinterpret_cast<char*>(&header), sizeof(header));
if (file.gcount() != sizeof(header))
{
std::cout << "Failed to read zone header from file '" << path << "'.\n";
return nullptr;