Add cppcoreguidelines-pro-bounds-array-to-pointer-decay clang-tidy check

Fix the warnings it emits.
This commit is contained in:
Oliver Hamlet
2022-02-07 00:15:58 +00:00
parent c4ef94ae46
commit 0792feaf8f
2 changed files with 7 additions and 6 deletions
+1
View File
@@ -491,6 +491,7 @@ if(RUN_CLANG_TIDY)
"cppcoreguidelines-macro-usage"
"cppcoreguidelines-narrowing-conventions"
"cppcoreguidelines-no-malloc"
"cppcoreguidelines-pro-bounds-array-to-pointer-decay"
"cppcoreguidelines-pro-bounds-constant-array-index"
"cppcoreguidelines-pro-bounds-pointer-arithmetic"
"cppcoreguidelines-pro-type-const-cast"
+6 -6
View File
@@ -55,17 +55,17 @@ uint32_t GetCrc32(const std::filesystem::path& filename) {
std::ifstream ifile(filename, std::ios::binary);
ifile.exceptions(std::ios_base::badbit | std::ios_base::failbit);
static const size_t bufferSize = 8192;
char buffer[bufferSize];
static constexpr size_t BUFFER_SIZE = 8192;
std::array<char, BUFFER_SIZE> buffer;
boost::crc_32_type result;
size_t bytesLeft = GetStreamSize(ifile);
while (bytesLeft > 0) {
if (bytesLeft > bufferSize)
ifile.read(buffer, bufferSize);
if (bytesLeft > buffer.size())
ifile.read(buffer.data(), buffer.size());
else
ifile.read(buffer, bytesLeft);
ifile.read(buffer.data(), bytesLeft);
result.process_bytes(buffer, ifile.gcount());
result.process_bytes(buffer.data(), ifile.gcount());
bytesLeft -= ifile.gcount();
}