Skip to content

Commit

Permalink
for clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
ban-nobuhiro committed Oct 8, 2023
1 parent 3fbcc05 commit 58caaa4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
12 changes: 6 additions & 6 deletions src/limestone/datastore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ datastore::datastore(configuration const& conf) : location_(conf.data_locations_
epoch_file_path_ = location_ / boost::filesystem::path(std::string(epoch_file_name));
const bool result = boost::filesystem::exists(epoch_file_path_, error);
if (!result || error) {
FILE* strm = fopen(epoch_file_path_.c_str(), "a"); // NOLINT(*-owning-memory)
FILE* strm = fopen(epoch_file_path_.c_str(), "a"); // LINT(*-owning-memory)

Check warning on line 58 in src/limestone/datastore.cpp

View workflow job for this annotation

GitHub Actions / Clang-Tidy

cppcoreguidelines-owning-memory

initializing non-owner 'FILE *' (aka '_IO_FILE *') with a newly created 'gsl::owner<>'
if (!strm) {
LOG_LP(ERROR) << "does not have write permission for the log_location directory, path: " << location_;
throw std::runtime_error("does not have write permission for the log_location directory");
}
if (fclose(strm) != 0) { // NOLINT(*-owning-memory)
if (fclose(strm) != 0) { // LINT(*-owning-memory)

Check warning on line 63 in src/limestone/datastore.cpp

View workflow job for this annotation

GitHub Actions / Clang-Tidy

cppcoreguidelines-owning-memory

calling legacy resource function without passing a 'gsl::owner<>'
LOG_LP(ERROR) << "fclose failed, errno = " << errno;
throw std::runtime_error("I/O error");
}
Expand Down Expand Up @@ -118,7 +118,7 @@ void datastore::switch_epoch(epoch_id_type new_epoch_id) noexcept {
update_min_epoch_id(true);
}

void datastore::update_min_epoch_id(bool from_switch_epoch) noexcept { // NOLINT(readability-function-cognitive-complexity)
void datastore::update_min_epoch_id(bool from_switch_epoch) noexcept { // LINT(readability-function-cognitive-complexity)

Check warning on line 121 in src/limestone/datastore.cpp

View workflow job for this annotation

GitHub Actions / Clang-Tidy

readability-function-cognitive-complexity

function 'update_min_epoch_id' has cognitive complexity of 32 (threshold 25)
auto upper_limit = epoch_id_switched_.load() - 1;
epoch_id_type max_finished_epoch = 0;

Expand Down Expand Up @@ -146,7 +146,7 @@ void datastore::update_min_epoch_id(bool from_switch_epoch) noexcept { // NOLIN
if (epoch_id_recorded_.compare_exchange_strong(old_epoch_id, to_be_epoch)) {
std::lock_guard<std::mutex> lock(mtx_epoch_file_);

FILE* strm = fopen(epoch_file_path_.c_str(), "a"); // NOLINT(*-owning-memory)
FILE* strm = fopen(epoch_file_path_.c_str(), "a"); // LINT(*-owning-memory)

Check warning on line 149 in src/limestone/datastore.cpp

View workflow job for this annotation

GitHub Actions / Clang-Tidy

cppcoreguidelines-owning-memory

initializing non-owner 'FILE *' (aka '_IO_FILE *') with a newly created 'gsl::owner<>'
if (!strm) {
LOG_LP(ERROR) << "fopen failed, errno = " << errno;
std::abort();
Expand All @@ -160,7 +160,7 @@ void datastore::update_min_epoch_id(bool from_switch_epoch) noexcept { // NOLIN
LOG_LP(ERROR) << "fsync failed, errno = " << errno;
std::abort();
}
if (fclose(strm) != 0) { // NOLINT(*-owning-memory)
if (fclose(strm) != 0) { // LINT(*-owning-memory)

Check warning on line 163 in src/limestone/datastore.cpp

View workflow job for this annotation

GitHub Actions / Clang-Tidy

cppcoreguidelines-owning-memory

calling legacy resource function without passing a 'gsl::owner<>'
LOG_LP(ERROR) << "fclose failed, errno = " << errno;
std::abort();
}
Expand Down Expand Up @@ -213,7 +213,7 @@ backup& datastore::begin_backup() {
return *backup_;
}

std::unique_ptr<backup_detail> datastore::begin_backup(backup_type btype) { // NOLINT(readability-function-cognitive-complexity)
std::unique_ptr<backup_detail> datastore::begin_backup(backup_type btype) { // LINT(readability-function-cognitive-complexity)

Check warning on line 216 in src/limestone/datastore.cpp

View workflow job for this annotation

GitHub Actions / Clang-Tidy

readability-function-cognitive-complexity

function 'begin_backup' has cognitive complexity of 28 (threshold 25)
rotate_log_files();

// LOG-0: all files are log file, so all files are selected in both standard/transaction mode.
Expand Down
14 changes: 7 additions & 7 deletions src/limestone/datastore_snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ epoch_id_type datastore::last_durable_epoch_in_dir() noexcept {

[[maybe_unused]]
static void store_bswap64_value(void *dest, const void *src) {
auto* p64_dest = reinterpret_cast<std::uint64_t*>(dest); // NOLINT(*-reinterpret-cast)
auto* p64_src = reinterpret_cast<const std::uint64_t*>(src); // NOLINT(*-reinterpret-cast)
auto* p64_dest = reinterpret_cast<std::uint64_t*>(dest); // LINT(*-reinterpret-cast)

Check warning on line 80 in src/limestone/datastore_snapshot.cpp

View workflow job for this annotation

GitHub Actions / Clang-Tidy

cppcoreguidelines-pro-type-reinterpret-cast

do not use reinterpret_cast
auto* p64_src = reinterpret_cast<const std::uint64_t*>(src); // LINT(*-reinterpret-cast)

Check warning on line 81 in src/limestone/datastore_snapshot.cpp

View workflow job for this annotation

GitHub Actions / Clang-Tidy

cppcoreguidelines-pro-type-reinterpret-cast

do not use reinterpret_cast
*p64_dest = __bswap_64(*p64_src);
}

Expand All @@ -92,7 +92,7 @@ static int comp_twisted_key(const std::string_view& a, const std::string_view& b
return std::memcmp(b.data(), a.data(), write_version_size);
}

void datastore::create_snapshot() noexcept { // NOLINT(readability-function-cognitive-complexity)
void datastore::create_snapshot() noexcept { // LINT(readability-function-cognitive-complexity)

Check warning on line 95 in src/limestone/datastore_snapshot.cpp

View workflow job for this annotation

GitHub Actions / Clang-Tidy

readability-function-cognitive-complexity

function 'create_snapshot' has cognitive complexity of 41 (threshold 25)
auto& from_dir = location_;
#if defined SORT_METHOD_PUT_ONLY
auto sortdb = std::make_unique<sortdb_wrapper>(from_dir, comp_twisted_key);
Expand Down Expand Up @@ -129,7 +129,7 @@ void datastore::create_snapshot() noexcept { // NOLINT(readability-function-cog
// key_sid: storage_id[8] key[*], value_etc: epoch[8]LE minor_version[8]LE value[*], type: type[1]
// db_key: epoch[8]BE minor_version[8]BE storage_id[8] key[*], db_value: type[1] value[*]
std::string db_key(write_version_size + e.key_sid().size(), '\0');
store_bswap64_value(&db_key[0], &e.value_etc()[0]); // NOLINT(readability-container-data-pointer)
store_bswap64_value(&db_key[0], &e.value_etc()[0]); // LINT(readability-container-data-pointer)

Check warning on line 132 in src/limestone/datastore_snapshot.cpp

View workflow job for this annotation

GitHub Actions / Clang-Tidy

readability-container-data-pointer

'data' should be used for accessing the data pointer instead of taking the address of the 0-th element

Check warning on line 132 in src/limestone/datastore_snapshot.cpp

View workflow job for this annotation

GitHub Actions / Clang-Tidy

readability-container-data-pointer

'data' should be used for accessing the data pointer instead of taking the address of the 0-th element
store_bswap64_value(&db_key[8], &e.value_etc()[8]);
std::memcpy(&db_key[write_version_size], e.key_sid().data(), e.key_sid().size());
std::string db_value(1, static_cast<char>(e.type()));
Expand Down Expand Up @@ -214,12 +214,12 @@ void datastore::create_snapshot() noexcept { // NOLINT(readability-function-cog

boost::filesystem::path snapshot_file = sub_dir / boost::filesystem::path(std::string(snapshot::file_name_));
VLOG_LP(log_info) << "generating snapshot file: " << snapshot_file;
FILE* ostrm = fopen(snapshot_file.c_str(), "w"); // NOLINT(*-owning-memory)
FILE* ostrm = fopen(snapshot_file.c_str(), "w"); // LINT(*-owning-memory)

Check warning on line 217 in src/limestone/datastore_snapshot.cpp

View workflow job for this annotation

GitHub Actions / Clang-Tidy

cppcoreguidelines-owning-memory

initializing non-owner 'FILE *' (aka '_IO_FILE *') with a newly created 'gsl::owner<>'
if (!ostrm) {
LOG_LP(ERROR) << "cannot create snapshot file (" << snapshot_file << ")";
std::abort();
}
setvbuf(ostrm, nullptr, _IOFBF, 128L * 1024L); // NOLINT, NB. glibc may ignore size when _IOFBF and buffer=NULL
setvbuf(ostrm, nullptr, _IOFBF, 128L * 1024L); // LINT, NB. glibc may ignore size when _IOFBF and buffer=NULL

Check warning on line 222 in src/limestone/datastore_snapshot.cpp

View workflow job for this annotation

GitHub Actions / Clang-Tidy

cert-err33-c

the value returned by this function should be used
static_assert(sizeof(log_entry::entry_type) == 1);
#if defined SORT_METHOD_PUT_ONLY
sortdb->each([&ostrm, last_key = std::string{}](std::string_view db_key, std::string_view db_value) mutable {
Expand Down Expand Up @@ -264,7 +264,7 @@ void datastore::create_snapshot() noexcept { // NOLINT(readability-function-cog
}
});
#endif
if (fclose(ostrm) != 0) { // NOLINT(*-owning-memory)
if (fclose(ostrm) != 0) { // LINT(*-owning-memory)

Check warning on line 267 in src/limestone/datastore_snapshot.cpp

View workflow job for this annotation

GitHub Actions / Clang-Tidy

cppcoreguidelines-owning-memory

calling legacy resource function without passing a 'gsl::owner<>'
LOG_LP(ERROR) << "cannot close snapshot file (" << snapshot_file << "), errno = " << errno;
std::abort();
}
Expand Down
6 changes: 3 additions & 3 deletions src/limestone/log_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ void log_channel::begin_session() noexcept {
} while (current_epoch_id_.load() != envelope_.epoch_id_switched_.load());

auto log_file = file_path();
strm_ = fopen(log_file.c_str(), "a"); // NOLINT(*-owning-memory)
strm_ = fopen(log_file.c_str(), "a"); // LINT(*-owning-memory)

Check warning on line 47 in src/limestone/log_channel.cpp

View workflow job for this annotation

GitHub Actions / Clang-Tidy

cppcoreguidelines-owning-memory

assigning newly created 'gsl::owner<>' to non-owner 'FILE *' (aka '_IO_FILE *')
if (!strm_) {
LOG_LP(ERROR) << "I/O error, cannot make file on " << location_ << ", errno = " << errno;
std::abort();
}
setvbuf(strm_, nullptr, _IOFBF, 128L * 1024L); // NOLINT, NB. glibc may ignore size when _IOFBF and buffer=NULL
setvbuf(strm_, nullptr, _IOFBF, 128L * 1024L); // LINT, NB. glibc may ignore size when _IOFBF and buffer=NULL

Check warning on line 52 in src/limestone/log_channel.cpp

View workflow job for this annotation

GitHub Actions / Clang-Tidy

cert-err33-c

the value returned by this function should be used
if (!registered_) {
envelope_.add_file(log_file);
registered_ = true;
Expand All @@ -69,7 +69,7 @@ void log_channel::end_session() noexcept {
finished_epoch_id_.store(current_epoch_id_.load());
current_epoch_id_.store(UINT64_MAX);
envelope_.update_min_epoch_id();
if (fclose(strm_) != 0) { // NOLINT(*-owning-memory)
if (fclose(strm_) != 0) { // LINT(*-owning-memory)

Check warning on line 72 in src/limestone/log_channel.cpp

View workflow job for this annotation

GitHub Actions / Clang-Tidy

cppcoreguidelines-owning-memory

calling legacy resource function without passing a 'gsl::owner<>'
LOG_LP(ERROR) << "fclose failed, errno = " << errno;
std::abort();
}
Expand Down
4 changes: 2 additions & 2 deletions src/limestone/log_entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class log_entry {
}
static std::uint32_t read_uint32le(std::istream& in) {
std::uint32_t buf{};
in.read(reinterpret_cast<char*>(&buf), sizeof(std::uint32_t)); // NOLINT(*-reinterpret-cast)
in.read(reinterpret_cast<char*>(&buf), sizeof(std::uint32_t)); // LINT(*-reinterpret-cast)

Check warning on line 255 in src/limestone/log_entry.h

View workflow job for this annotation

GitHub Actions / Clang-Tidy

cppcoreguidelines-pro-type-reinterpret-cast

do not use reinterpret_cast
return le32toh(buf);
}
static void write_uint64le(FILE* out, const std::uint64_t value) {
Expand All @@ -261,7 +261,7 @@ class log_entry {
}
static std::uint64_t read_uint64le(std::istream& in) {
std::uint64_t buf{};
in.read(reinterpret_cast<char*>(&buf), sizeof(std::uint64_t)); // NOLINT(*-reinterpret-cast)
in.read(reinterpret_cast<char*>(&buf), sizeof(std::uint64_t)); // LINT(*-reinterpret-cast)

Check warning on line 264 in src/limestone/log_entry.h

View workflow job for this annotation

GitHub Actions / Clang-Tidy

cppcoreguidelines-pro-type-reinterpret-cast

do not use reinterpret_cast
return le64toh(buf);
}
static void write_bytes(FILE* out, const void* buf, std::size_t len) {
Expand Down
4 changes: 2 additions & 2 deletions src/limestone/logging_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ constexpr auto location_prefix(const std::string_view sv) {
}

template<size_t N, size_t M>
constexpr auto location_prefix(const char (&prettyname)[N], const char (&funcname)[M]) { // NOLINT(*-avoid-c-arrays)
const std::string_view sv = find_fullname(prettyname, funcname); // NOLINT(*-bounds-array-to-pointer-decay)
constexpr auto location_prefix(const char (&prettyname)[N], const char (&funcname)[M]) { // LINT(*-avoid-c-arrays)

Check warning on line 88 in src/limestone/logging_helper.h

View workflow job for this annotation

GitHub Actions / Clang-Tidy

cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays

do not declare C-style arrays, use std::array<> instead

Check warning on line 88 in src/limestone/logging_helper.h

View workflow job for this annotation

GitHub Actions / Clang-Tidy

cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays

do not declare C-style arrays, use std::array<> instead
const std::string_view sv = find_fullname(prettyname, funcname); // LINT(*-bounds-array-to-pointer-decay)

Check warning on line 89 in src/limestone/logging_helper.h

View workflow job for this annotation

GitHub Actions / Clang-Tidy

cppcoreguidelines-pro-bounds-array-to-pointer-decay

do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead

Check warning on line 89 in src/limestone/logging_helper.h

View workflow job for this annotation

GitHub Actions / Clang-Tidy

cppcoreguidelines-pro-bounds-array-to-pointer-decay

do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead
return location_prefix<std::max(N, M)>(sv);
}

Expand Down
4 changes: 2 additions & 2 deletions src/limestone/sortdb_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ class sortdb_wrapper {
}

void each(const std::function<void(std::string_view, std::string_view)>& fun) {
Iterator* it = sortdb_->NewIterator(ReadOptions()); // NOLINT (typical usage of API)
Iterator* it = sortdb_->NewIterator(ReadOptions()); // LINT (typical usage of API)
for (it->SeekToFirst(); it->Valid(); it->Next()) {
Slice key = it->key();
Slice value = it->value();
fun(std::string_view(key.data(), key.size()), std::string_view(value.data(), value.size()));
}
delete it; // NOLINT (typical usage of API)
delete it; // LINT (typical usage of API)

Check warning on line 98 in src/limestone/sortdb_wrapper.h

View workflow job for this annotation

GitHub Actions / Clang-Tidy

cppcoreguidelines-owning-memory

deleting a pointer through a type that is not marked 'gsl::owner<>'; consider using a smart pointer instead
}

private:
Expand Down

0 comments on commit 58caaa4

Please sign in to comment.