Skip to content

Commit

Permalink
fix(clang-tidy): modernize-use-nullptr
Browse files Browse the repository at this point in the history
Signed-off-by: atsushi421 <atsushi.yano.2@tier4.jp>
  • Loading branch information
atsushi421 committed Dec 3, 2024
1 parent 19f4bfa commit f073e04
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
2 changes: 0 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Checks: "
-cppcoreguidelines-pro-type-reinterpret-cast,
-cppcoreguidelines-pro-type-union-access,
-cppcoreguidelines-pro-type-vararg,
-cppcoreguidelines-special-member-functions,
-cppcoreguidelines-avoid-non-const-global-variables,
google-*,
Expand All @@ -33,7 +32,6 @@ Checks: "
modernize-*,
-modernize-avoid-bind,
-modernize-pass-by-value,
-modernize-use-nullptr,
-modernize-use-trailing-return-type,
performance-*,
Expand Down
8 changes: 8 additions & 0 deletions docs/clang_tidy_suppression.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ This is difficult to avoid, as it requires a major change to the implementation.

In the current logic, `reinterpret-cast` is essential.

## cppcoreguidelines-pro-type-vararg, hicpp-vararg

These cannot be resolved while using `ioctl`.

## cppcoreguidelines-pro-type-union-access

This is difficult to avoid, as it prohibits the use of `union`.

## google-build-using-namespace

This cannot be resolved while using gmock-global. This is due to [this issue](https://github.com/apriorit/gmock-global/issues/5).
16 changes: 8 additions & 8 deletions src/agnocastlib/src/agnocast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void * map_area(
if (shm_fd == -1) {
RCLCPP_ERROR(logger, "shm_open failed: %s", strerror(errno));
close(agnocast_fd);
return NULL;
return nullptr;
}

{
Expand All @@ -58,7 +58,7 @@ void * map_area(
if (ftruncate(shm_fd, static_cast<off_t>(shm_size)) == -1) {
RCLCPP_ERROR(logger, "ftruncate failed: %s", strerror(errno));
close(agnocast_fd);
return NULL;
return nullptr;
}
}

Expand All @@ -70,7 +70,7 @@ void * map_area(
if (ret == MAP_FAILED) {
RCLCPP_ERROR(logger, "mmap failed: %s", strerror(errno));
close(agnocast_fd);
return NULL;
return nullptr;
}

return ret;
Expand All @@ -81,7 +81,7 @@ void * map_writable_area(const uint32_t pid, const uint64_t shm_addr, const uint
if (already_mapped(pid)) {
RCLCPP_ERROR(logger, "map_writeable_area failed");
close(agnocast_fd);
return NULL;
return nullptr;
}

return map_area(pid, shm_addr, shm_size, true);
Expand All @@ -92,7 +92,7 @@ void map_read_only_area(const uint32_t pid, const uint64_t shm_addr, const uint6
if (already_mapped(pid)) {
return;
}
if (map_area(pid, shm_addr, shm_size, false) == NULL) {
if (map_area(pid, shm_addr, shm_size, false) == nullptr) {
exit(EXIT_FAILURE);
}
}
Expand All @@ -102,13 +102,13 @@ void * initialize_agnocast(const uint64_t shm_size)
{
if (agnocast_fd >= 0) {
RCLCPP_ERROR(logger, "Agnocast is already open");
return NULL;
return nullptr;
}

agnocast_fd = open("/dev/agnocast", O_RDWR);
if (agnocast_fd < 0) {
RCLCPP_ERROR(logger, "Failed to open the device: %s", strerror(errno));
return NULL;
return nullptr;
}

const uint32_t pid = getpid();
Expand All @@ -119,7 +119,7 @@ void * initialize_agnocast(const uint64_t shm_size)
if (ioctl(agnocast_fd, AGNOCAST_NEW_SHM_CMD, &new_shm_args) < 0) {
RCLCPP_ERROR(logger, "AGNOCAST_NEW_SHM_CMD failed");
close(agnocast_fd);
return NULL;
return nullptr;
}
return map_writable_area(pid, new_shm_args.ret_addr, shm_size);
}
Expand Down
3 changes: 2 additions & 1 deletion src/agnocastlib/src/agnocast_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ bool AgnocastExecutor::get_next_agnocast_executables(
MqMsgAgnocast mq_msg = {};

// non-blocking
auto ret = mq_receive(topic_info.mqdes, reinterpret_cast<char *>(&mq_msg), sizeof(mq_msg), NULL);
auto ret =
mq_receive(topic_info.mqdes, reinterpret_cast<char *>(&mq_msg), sizeof(mq_msg), nullptr);
if (ret < 0) {
if (errno != EAGAIN) {
RCLCPP_ERROR(logger, "mq_receive failed: %s", strerror(errno));
Expand Down
2 changes: 1 addition & 1 deletion src/agnocastlib/src/agnocast_subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void SubscriptionBase::wait_for_new_publisher() const
auto th = std::thread([=]() {
while (agnocast::ok()) {
MqMsgNewPublisher mq_msg = {};
auto ret = mq_receive(mq, reinterpret_cast<char *>(&mq_msg), sizeof(mq_msg), NULL);
auto ret = mq_receive(mq, reinterpret_cast<char *>(&mq_msg), sizeof(mq_msg), nullptr);
if (ret == -1) {
RCLCPP_ERROR(logger, "mq_receive for new publisher failed: %s", strerror(errno));
close(agnocast_fd);
Expand Down

0 comments on commit f073e04

Please sign in to comment.