-ConfigurationNotChecked
-missingIncludeSystem
-
// Ignore third party code.
-*:src/third_party
+*:*/third_party/*
+
+// Not interesting enough to enforce.
+noExplicitConstructor
Args compiler_args;
// Whether to include the actual CWD in the hash.
- bool hash_actual_cwd;
+ bool hash_actual_cwd = false;
};
inline ProcessArgsResult::ProcessArgsResult(core::Statistic error_)
do_cache_compilation(Context& ctx);
static void
-log_result_to_debug_log(Context& ctx)
+log_result_to_debug_log(const Context& ctx)
{
if (ctx.config.log_file().empty() && !ctx.config.debug()) {
return;
hash.hash_delimiter("timestamp");
#ifdef HAVE_ASCTIME_R
char buffer[26];
- auto timestamp = asctime_r(&*modified_time, buffer);
+ const char* timestamp = asctime_r(&*modified_time, buffer);
#else
- auto timestamp = asctime(&*modified_time);
+ // cppcheck-suppress asctimeCalled; thread-safety not needed here
+ const char* timestamp = asctime(&*modified_time);
#endif
if (!timestamp) {
result.insert(HashSourceCode::error);
void
LocalStorage::put_raw_files(
const Hash::Digest& key,
- const std::vector<core::Result::Serializer::RawFile> raw_files)
+ const std::vector<core::Result::Serializer::RawFile>& raw_files)
{
const auto cache_file = look_up_cache_file(key, core::CacheEntryType::result);
core::ensure_dir_exists(fs::path(cache_file.path).parent_path());
std::string get_raw_file_path(const Hash::Digest& result_key,
uint8_t file_number) const;
- void
- put_raw_files(const Hash::Digest& key,
- const std::vector<core::Result::Serializer::RawFile> raw_files);
+ void put_raw_files(
+ const Hash::Digest& key,
+ const std::vector<core::Result::Serializer::RawFile>& raw_files);
// Clone, hard link or copy a file from `source` to `dest` depending on
// settings in `ctx`. If cloning or hard linking cannot and should not be done
Bytes::reserve(size_t size) noexcept
{
if (size > m_capacity) {
- auto data = std::make_unique<uint8_t[]>(size);
+ auto bytes = std::make_unique<uint8_t[]>(size);
if (m_size > 0) {
- std::memcpy(data.get(), m_data.get(), m_size);
+ std::memcpy(bytes.get(), m_data.get(), m_size);
}
- m_data = std::move(data);
+ m_data = std::move(bytes);
m_capacity = size;
}
}
} else
#endif
{
- auto path = pstr(m_path);
- result = lstat_func(path, &m_stat);
+ auto mpath = pstr(m_path);
+ result = lstat_func(mpath, &m_stat);
if (result == 0) {
if (S_ISLNK(m_stat.st_mode)
#ifdef _WIN32
) {
m_is_symlink = true;
stat_t st;
- if (stat_func(path, &st) == 0) {
+ if (stat_func(mpath, &st) == 0) {
m_stat = st;
m_exists = true;
}
#ifndef _WIN32
const void* MMAP_FAILED =
reinterpret_cast<void*>(-1); // NOLINT: Must cast here
- void* ptr = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
- if (ptr == MMAP_FAILED) {
+ void* p = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ if (p == MMAP_FAILED) {
return tl::unexpected(strerror(errno));
}
MemoryMap map;
- map.m_ptr = ptr;
+ map.m_ptr = p;
map.m_size = size;
return map;
#else
return tl::unexpected(FMT("Can't create file mapping: {}", GetLastError()));
}
- void* ptr =
- MapViewOfFile(file_mapping_handle, FILE_MAP_ALL_ACCESS, 0, 0, size);
- if (!ptr) {
+ void* p = MapViewOfFile(file_mapping_handle, FILE_MAP_ALL_ACCESS, 0, 0, size);
+ if (!p) {
std::string error = FMT("Can't map file: {}", GetLastError());
CloseHandle(file_mapping_handle);
return tl::unexpected(std::move(error));
}
MemoryMap map;
- map.m_ptr = ptr;
+ map.m_ptr = p;
map.m_file_mapping_handle = file_mapping_handle;
return map;
#endif
}
snprintf(prefix,
sizeof(prefix),
- "[%s.%06d %-5d] ",
+ "[%s.%06u %-5d] ",
timestamp,
static_cast<unsigned int>(now.nsec_decimal_part() / 1000),
static_cast<int>(getpid()));
std::string result;
size_t left = 0;
- size_t right = 0;
while (left < string.size()) {
- right = string.find(from, left);
+ size_t right = string.find(from, left);
if (right == std::string_view::npos) {
result.append(string.data() + left);
break;
SUBCASE("Move construction")
{
- const auto bytes1_orig_data = bytes1.data();
+ // cppcheck-suppress constVariablePointer; we're intentionally keeping a
+ // copy of the pointer
+ const uint8_t* bytes1_orig_data = bytes1.data();
Bytes bytes2(std::move(bytes1));
CHECK(bytes1.data() == nullptr);
SUBCASE("Move assignment")
{
- const auto bytes1_orig_data = bytes1.data();
+ // cppcheck-suppress constVariablePointer; we're intentionally keeping a
+ // copy of the pointer
+ const uint8_t* bytes1_orig_data = bytes1.data();
Bytes bytes2;
bytes2 = std::move(bytes1);
SUBCASE("Non-const operator[]")
{
bytes1[1] = 'x';
- CHECK(bytes1[1] == 'x');
+ CHECK(bytes1[1] == 'x'); // cppcheck-suppress knownConditionTrueFalse
}
SUBCASE("Comparison")
SUBCASE("Reserve and capacity")
{
- const auto bytes1_orig_data = bytes1.data();
+ // cppcheck-suppress constVariablePointer; we're intentionally keeping a
+ // copy of the pointer
+ const uint8_t* bytes1_orig_data = bytes1.data();
CHECK(bytes1.size() == 3);
CHECK(bytes1.capacity() == 3);
SUBCASE("Increase size")
{
- const auto bytes1_orig_data = bytes1.data();
+ // cppcheck-suppress constVariablePointer; we're intentionally keeping a
+ // copy of the pointer
+ const uint8_t* bytes1_orig_data = bytes1.data();
bytes1.resize(4);
CHECK(bytes1.data() != bytes1_orig_data);
CHECK(bytes1.size() == 4);
SUBCASE("Decrease size")
{
- const auto bytes1_orig_data = bytes1.data();
+ // cppcheck-suppress constVariablePointer; we're intentionally keeping a
+ // copy of the pointer
+ const uint8_t* bytes1_orig_data = bytes1.data();
bytes1.resize(2);
CHECK(bytes1.data() == bytes1_orig_data);
CHECK(bytes1.size() == 2);
TEST_CASE("util::likely_size_on_disk")
{
+ // cppcheck-suppress knownConditionTrueFalse
CHECK(util::likely_size_on_disk(0) == 0);
+ // cppcheck-suppress knownConditionTrueFalse
CHECK(util::likely_size_on_disk(1) == 4096);
+ // cppcheck-suppress knownConditionTrueFalse
CHECK(util::likely_size_on_disk(4095) == 4096);
+ // cppcheck-suppress knownConditionTrueFalse
CHECK(util::likely_size_on_disk(4096) == 4096);
+ // cppcheck-suppress knownConditionTrueFalse
CHECK(util::likely_size_on_disk(4097) == 8192);
}