Skip to content

Commit

Permalink
refactor: fix hicpp-no-malloc lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Oct 17, 2024
1 parent 8740c8b commit fdb9bd4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Checks: >-
hicpp*,
-hicpp-avoid-c-arrays,
-hicpp-no-array-decay,
-hicpp-no-malloc,
-hicpp-signed-bitwise,
-hicpp-vararg,
misc*,
Expand Down
2 changes: 1 addition & 1 deletion src/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ unsigned char *os_map_file(const char *path, uint64_t length, bool shared) {
}

// use calloc to improve performance
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc)
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc,hicpp-no-malloc)
auto host_memory = static_cast<unsigned char *>(std::calloc(1, length));
if (!host_memory) {
throw std::runtime_error{"error allocating memory"s};
Expand Down
4 changes: 2 additions & 2 deletions src/pma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void pma_memory::release() {
os_unmap_file(m_host_memory, m_length);
m_mmapped = false;
} else {
std::free(m_host_memory); // NOLINT(cppcoreguidelines-no-malloc)
std::free(m_host_memory); // NOLINT(cppcoreguidelines-no-malloc,hicpp-no-malloc)
}
m_host_memory = nullptr;
m_length = 0;
Expand All @@ -58,7 +58,7 @@ pma_memory::pma_memory(const std::string &description, uint64_t length, const ca
m_host_memory{nullptr},
m_mmapped{false} {
// use calloc to improve performance
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc, cppcoreguidelines-prefer-member-initializer)
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc,hicpp-no-malloc,cppcoreguidelines-prefer-member-initializer)
m_host_memory = static_cast<unsigned char *>(std::calloc(1, length));
if (m_host_memory == nullptr) {
throw std::runtime_error{"error allocating memory for "s + description};
Expand Down
6 changes: 3 additions & 3 deletions src/unique-c-ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace detail {
struct free_deleter {
template <typename T>
void operator()(T *p) const {
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc, cppcoreguidelines-pro-type-const-cast)
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc,hicpp-no-malloc,cppcoreguidelines-pro-type-const-cast)
std::free(const_cast<std::remove_const_t<T> *>(p));
}
};
Expand All @@ -48,7 +48,7 @@ using unique_file_ptr = std::unique_ptr<FILE, detail::fclose_deleter>;

template <typename T>
static inline unique_calloc_ptr<T> unique_calloc(size_t nmemb) {
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc)
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc,hicpp-no-malloc)
T *ptr = static_cast<T *>(calloc(nmemb, sizeof(T)));
if (!ptr) {
throw std::bad_alloc{}; // LCOV_EXCL_LINE
Expand All @@ -58,7 +58,7 @@ static inline unique_calloc_ptr<T> unique_calloc(size_t nmemb) {

template <typename T>
static inline unique_calloc_ptr<T> unique_calloc(size_t nmemb, const std::nothrow_t & /*tag*/) {
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc)
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc,hicpp-no-malloc)
return unique_calloc_ptr<T>(static_cast<T *>(calloc(nmemb, sizeof(T))));
}

Expand Down

0 comments on commit fdb9bd4

Please sign in to comment.