Resolve clang-tidy warnings (#172)

This commit is contained in:
Victor Derks 2022-02-04 23:20:03 +01:00 committed by GitHub
parent 461df4b0e6
commit 283882874c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 29 additions and 31 deletions

View File

@ -7,6 +7,7 @@
#include <cstdint>
#include <memory>
#include <vector>
#pragma warning(disable : 26409) // Avoid calling new explicitly (triggered by BENCHMARK macro)
@ -160,7 +161,7 @@ inline int countl_zero(const uint64_t value) noexcept
unsigned long index;
_BitScanReverse64(&index, value);
return 63 - index;
return 63 - static_cast<int>(index);
}
#endif

View File

@ -275,7 +275,7 @@ public:
typename T2 = typename DestinationContainer::value_type>
static std::pair<charls::frame_info, charls::interleave_mode>
decode(const SourceContainer& source, DestinationContainer& destination,
const size_t maximum_size_in_bytes = 7680 * 4320 * 3)
const size_t maximum_size_in_bytes = static_cast<size_t>(7680) * 4320 * 3)
{
jpegls_decoder decoder{source, true};

View File

@ -51,7 +51,7 @@ public:
const int bytes_per_sample = (bits_per_sample_ + 7) / 8;
input_buffer_.resize(static_cast<size_t>(width_) * height_ * bytes_per_sample * component_count_);
pnm_file.read(reinterpret_cast<char*>(input_buffer_.data()), input_buffer_.size());
pnm_file.read(reinterpret_cast<char*>(input_buffer_.data()), static_cast<std::streamsize>(input_buffer_.size()));
convert_to_little_endian_if_needed();
}

View File

@ -45,7 +45,7 @@ public:
const std::error_category& category{jpegls_category()};
const std::string message{category.message(0)};
Assert::IsTrue(message.size() > 0);
Assert::IsFalse(message.empty());
}
};

View File

@ -16,7 +16,6 @@
using Microsoft::VisualStudio::CppUnitTestFramework::Assert;
using std::array;
using std::numeric_limits;
using std::system_error;
using std::vector;
namespace charls { namespace test {

View File

@ -876,7 +876,7 @@ public:
TEST_METHOD(encode_1_component_4_bit_with_high_bits_set) // NOLINT
{
const vector<uint8_t> source(512 * 512, 0xFF);
const vector<uint8_t> source(static_cast<size_t>(512) * 512, 0xFF);
constexpr frame_info frame_info{512, 512, 4, 1};
jpegls_encoder encoder;
@ -888,13 +888,13 @@ public:
const size_t bytes_written{encoder.encode(source)};
destination.resize(bytes_written);
const vector<uint8_t> expected(512 * 512, 15);
const vector<uint8_t> expected(static_cast<size_t>(512) * 512, 15);
test_by_decoding(destination, frame_info, expected.data(), expected.size(), interleave_mode::none);
}
TEST_METHOD(encode_1_component_12_bit_with_high_bits_set) // NOLINT
{
const vector<uint8_t> source(512 * 512 * 2, 0xFF);
const vector<uint8_t> source(static_cast<size_t>(512) * 512 * 2, 0xFF);
constexpr frame_info frame_info{512, 512, 12, 1};
jpegls_encoder encoder;
@ -906,14 +906,14 @@ public:
const size_t bytes_written{encoder.encode(source)};
destination.resize(bytes_written);
const vector<uint16_t> expected(512 * 512, 4095);
const vector<uint16_t> expected(static_cast<size_t>(512) * 512, 4095);
test_by_decoding(destination, frame_info, expected.data(), expected.size() * sizeof(uint16_t),
interleave_mode::none);
}
TEST_METHOD(encode_3_components_6_bit_with_high_bits_set_interleave_mode_sample) // NOLINT
{
const vector<uint8_t> source(512 * 512 * 3, 0xFF);
const vector<uint8_t> source(static_cast<size_t>(512) * 512 * 3, 0xFF);
constexpr frame_info frame_info{512, 512, 6, 3};
jpegls_encoder encoder;
@ -925,13 +925,13 @@ public:
const size_t bytes_written{encoder.encode(source)};
destination.resize(bytes_written);
const vector<uint8_t> expected(512 * 512 * 3, 63);
const vector<uint8_t> expected(static_cast<size_t>(512) * 512 * 3, 63);
test_by_decoding(destination, frame_info, expected.data(), expected.size(), interleave_mode::sample);
}
TEST_METHOD(encode_3_components_6_bit_with_high_bits_set_interleave_mode_line) // NOLINT
{
const vector<uint8_t> source(512 * 512 * 3, 0xFF);
const vector<uint8_t> source(static_cast<size_t>(512) * 512 * 3, 0xFF);
constexpr frame_info frame_info{512, 512, 6, 3};
jpegls_encoder encoder;
@ -943,13 +943,13 @@ public:
const size_t bytes_written{encoder.encode(source)};
destination.resize(bytes_written);
const vector<uint8_t> expected(512 * 512 * 3, 63);
const vector<uint8_t> expected(static_cast<size_t>(512) * 512 * 3, 63);
test_by_decoding(destination, frame_info, expected.data(), expected.size(), interleave_mode::line);
}
TEST_METHOD(encode_3_components_10_bit_with_high_bits_set_interleave_mode_sample) // NOLINT
{
const vector<uint8_t> source(512 * 512 * 2 * 3, 0xFF);
const vector<uint8_t> source(static_cast<size_t>(512) * 512 * 2 * 3, 0xFF);
constexpr frame_info frame_info{512, 512, 10, 3};
jpegls_encoder encoder;
@ -961,13 +961,13 @@ public:
const size_t bytes_written{encoder.encode(source)};
destination.resize(bytes_written);
const vector<uint16_t> expected(512 * 512 * 3, 1023);
const vector<uint16_t> expected(static_cast<size_t>(512) * 512 * 3, 1023);
test_by_decoding(destination, frame_info, expected.data(), expected.size() * 2, interleave_mode::sample);
}
TEST_METHOD(encode_3_components_10_bit_with_high_bits_set_interleave_mode_line) // NOLINT
{
const vector<uint8_t> source(512 * 512 * 2 * 3, 0xFF);
const vector<uint8_t> source(static_cast<size_t>(512) * 512 * 2 * 3, 0xFF);
constexpr frame_info frame_info{512, 512, 10, 3};
jpegls_encoder encoder;
@ -979,13 +979,13 @@ public:
const size_t bytes_written{encoder.encode(source)};
destination.resize(bytes_written);
const vector<uint16_t> expected(512 * 512 * 3, 1023);
const vector<uint16_t> expected(static_cast<size_t>(512) * 512 * 3, 1023);
test_by_decoding(destination, frame_info, expected.data(), expected.size() * 2, interleave_mode::line);
}
TEST_METHOD(encode_4_components_6_bit_with_high_bits_set_interleave_mode_sample) // NOLINT
{
const vector<uint8_t> source(512 * 512 * 4, 0xFF);
const vector<uint8_t> source(static_cast<size_t>(512) * 512 * 4, 0xFF);
constexpr frame_info frame_info{512, 512, 6, 4};
jpegls_encoder encoder;
@ -997,13 +997,13 @@ public:
const size_t bytes_written{encoder.encode(source)};
destination.resize(bytes_written);
const vector<uint8_t> expected(512 * 512 * 4, 63);
const vector<uint8_t> expected(static_cast<size_t>(512) * 512 * 4, 63);
test_by_decoding(destination, frame_info, expected.data(), expected.size(), interleave_mode::sample);
}
TEST_METHOD(encode_4_components_6_bit_with_high_bits_set_interleave_mode_line) // NOLINT
{
const vector<uint8_t> source(512 * 512 * 4, 0xFF);
const vector<uint8_t> source(static_cast<size_t>(512) * 512 * 4, 0xFF);
constexpr frame_info frame_info{512, 512, 6, 4};
jpegls_encoder encoder;
@ -1015,13 +1015,13 @@ public:
const size_t bytes_written{encoder.encode(source)};
destination.resize(bytes_written);
const vector<uint8_t> expected(512 * 512 * 4, 63);
const vector<uint8_t> expected(static_cast<size_t>(512) * 512 * 4, 63);
test_by_decoding(destination, frame_info, expected.data(), expected.size(), interleave_mode::line);
}
TEST_METHOD(encode_4_components_10_bit_with_high_bits_set_interleave_mode_sample) // NOLINT
{
const vector<uint8_t> source(512 * 512 * 2 * 4, 0xFF);
const vector<uint8_t> source(static_cast<size_t>(512) * 512 * 2 * 4, 0xFF);
constexpr frame_info frame_info{512, 512, 10, 4};
jpegls_encoder encoder;
@ -1033,13 +1033,13 @@ public:
const size_t bytes_written{encoder.encode(source)};
destination.resize(bytes_written);
const vector<uint16_t> expected(512 * 512 * 4, 1023);
const vector<uint16_t> expected(static_cast<size_t>(512) * 512 * 4, 1023);
test_by_decoding(destination, frame_info, expected.data(), expected.size() * 2, interleave_mode::sample);
}
TEST_METHOD(encode_4_components_10_bit_with_high_bits_set_interleave_mode_line) // NOLINT
{
const vector<uint8_t> source(512 * 512 * 2 * 4, 0xFF);
const vector<uint8_t> source(static_cast<size_t>(512) * 512 * 2 * 4, 0xFF);
constexpr frame_info frame_info{512, 512, 10, 4};
jpegls_encoder encoder;
@ -1051,7 +1051,7 @@ public:
const size_t bytes_written{encoder.encode(source)};
destination.resize(bytes_written);
const vector<uint16_t> expected(512 * 512 * 4, 1023);
const vector<uint16_t> expected(static_cast<size_t>(512) * 512 * 4, 1023);
test_by_decoding(destination, frame_info, expected.data(), expected.size() * 2, interleave_mode::line);
}
@ -1335,15 +1335,15 @@ public:
vector<uint8_t> destination(encoder.estimated_destination_size());
void* data1 = destination.data();
const uint16_t size1 = static_cast<uint16_t>(destination.size());
const auto size1 = static_cast<uint16_t>(destination.size());
encoder.destination(data1, size1);
vector<uint8_t> source(static_cast<size_t>(frame_info.width) * frame_info.height);
void* data2 = source.data();
const uint16_t size2 = static_cast<uint16_t>(source.size());
const auto size2 = static_cast<uint16_t>(source.size());
// Set 1 value to prevent complains about const.
uint8_t* p = static_cast<uint8_t*>(data2);
auto* p = static_cast<uint8_t*>(data2);
*p = 7;
// size2 is not a perfect match and needs a conversion.

View File

@ -9,7 +9,6 @@
using Microsoft::VisualStudio::CppUnitTestFramework::Assert;
using std::vector;
using std::numeric_limits;
namespace {

View File

@ -52,7 +52,7 @@ vector<uint8_t> read_file(const char* filename)
input.seekg(0, ios::beg);
vector<uint8_t> buffer(byte_count_file);
input.read(reinterpret_cast<char*>(buffer.data()), buffer.size());
input.read(reinterpret_cast<char*>(buffer.data()), static_cast<std::streamsize>(buffer.size()));
return buffer;
}

View File

@ -6,7 +6,6 @@
#include "../src/util.h"
using Microsoft::VisualStudio::CppUnitTestFramework::Assert;
using std::array;
using std::numeric_limits;
namespace charls { namespace test {