Skip to content

Commit 9a12b61

Browse files
committed
fix clang analyzer "error: Called C++ object pointer is null" error
1 parent c0ad95e commit 9a12b61

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

include/libcyphal/presentation/client.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,13 @@ class ClientBase
9292

9393
ClientBase& operator=(ClientBase&& other) noexcept
9494
{
95-
CETL_DEBUG_ASSERT(shared_client_ != nullptr, "Not supposed to move construct to already moved `this`.");
9695
CETL_DEBUG_ASSERT(other.shared_client_ != nullptr,
9796
"Not supposed to move construct from already moved `other`.");
9897

99-
(void) shared_client_->release();
98+
if (nullptr != shared_client_)
99+
{
100+
(void) shared_client_->release();
101+
}
100102

101103
shared_client_ = std::exchange(other.shared_client_, nullptr);
102104
priority_ = other.priority_;

include/libcyphal/presentation/publisher.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ class PublisherBase
7878

7979
PublisherBase& operator=(PublisherBase&& other) noexcept
8080
{
81-
CETL_DEBUG_ASSERT(impl_ != nullptr, "Not supposed to move to already moved `this`.");
8281
CETL_DEBUG_ASSERT(other.impl_ != nullptr, "Not supposed to move from already moved `other`.");
8382

84-
(void) impl_->release();
83+
if (nullptr != impl_)
84+
{
85+
(void) impl_->release();
86+
}
8587

8688
impl_ = std::exchange(other.impl_, nullptr);
8789
priority_ = other.priority_;

include/libcyphal/presentation/subscriber.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ class SubscriberBase : public SubscriberImpl::CallbackNode
5050

5151
SubscriberBase& operator=(SubscriberBase&& other) noexcept
5252
{
53-
CETL_DEBUG_ASSERT(impl_ != nullptr, "Not supposed to move to already moved `this`.");
53+
CETL_DEBUG_ASSERT(other.impl_ != nullptr, "Not supposed to move from already moved `other`.");
5454

55-
impl_->releaseCallbackNode(*this);
55+
if (nullptr != impl_)
56+
{
57+
impl_->releaseCallbackNode(*this);
58+
}
5659

5760
impl_ = std::exchange(other.impl_, nullptr);
5861

0 commit comments

Comments
 (0)