Skip to content

Commit

Permalink
fix: bug when take null (#319)
Browse files Browse the repository at this point in the history
* fix: bug when take null

Signed-off-by: atsushi421 <atsushi.yano.2@tier4.jp>

* fix

* fix

---------

Signed-off-by: atsushi421 <atsushi.yano.2@tier4.jp>
  • Loading branch information
atsushi421 authored Dec 9, 2024
1 parent 9bb6e15 commit 013f25b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/agnocastlib/include/agnocast_smart_pointer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ipc_shared_ptr
timestamp_(r.timestamp_),
is_created_by_sub_(r.is_created_by_sub_)
{
if (!is_created_by_sub_) {
if (ptr_ != nullptr && !is_created_by_sub_) {
RCLCPP_ERROR(
logger,
"Copying an ipc_shared_ptr is not allowed if it was created by borrow_loaned_message().");
Expand Down
8 changes: 8 additions & 0 deletions src/agnocastlib/test/test_agnocast_smart_pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ TEST_F(AgnocastSmartPointerTest, copy_constructor_isnt_created_by_sub)
"Copying an ipc_shared_ptr is not allowed if it was created by borrow_loaned_message().");
}

TEST_F(AgnocastSmartPointerTest, copy_constructor_empty)
{
EXPECT_GLOBAL_CALL(increment_rc_core, increment_rc_core(dummy_tn, dummy_pid, dummy_ts)).Times(0);
EXPECT_GLOBAL_CALL(decrement_rc, decrement_rc(dummy_tn, dummy_pid, dummy_ts)).Times(0);
agnocast::ipc_shared_ptr<int> sut;
EXPECT_NO_THROW(agnocast::ipc_shared_ptr<int> sut2{sut});
}

TEST_F(AgnocastSmartPointerTest, move_constructor_normal)
{
int * ptr = new int(0);
Expand Down

0 comments on commit 013f25b

Please sign in to comment.