Skip to content

Commit 76f2877

Browse files
committed
Refs #24365: Fix UB in RTPSStatisticsTests magically
Signed-off-by: Carlos Ferreira González <carlosferreira@eprosima.com>
1 parent 9b163ca commit 76f2877

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

test/unittest/statistics/rtps/RTPSStatisticsTests.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,28 @@ namespace fastdds {
5757
namespace statistics {
5858
namespace rtps {
5959

60-
class RTPSParticipantMock : public fastdds::rtps::RTPSParticipant
61-
{
60+
namespace {
6261

63-
public:
62+
// Accessor to RTPSParticipantImpl* from RTPSParticipant
63+
using RTPSParticipantImplPtr = fastdds::rtps::RTPSParticipantImpl * fastdds::rtps::RTPSParticipant::*;
6464

65-
fastdds::rtps::RTPSParticipantImpl* get_impl()
65+
RTPSParticipantImplPtr get_rtps_part_impl();
66+
67+
template<RTPSParticipantImplPtr P>
68+
struct RTPSParticipantImplAccessor
69+
{
70+
friend RTPSParticipantImplPtr get_rtps_part_impl()
6671
{
67-
return mp_impl;
72+
return P;
6873
}
6974

70-
private:
71-
72-
~RTPSParticipantMock() = default;
7375
};
7476

77+
template struct RTPSParticipantImplAccessor<&fastdds::rtps::RTPSParticipant::mp_impl>;
78+
79+
} // namespace
80+
81+
7582
struct MockListener : IListener
7683
{
7784
MockListener()
@@ -1394,8 +1401,7 @@ TEST_F(RTPSStatisticsTests, iconnections_queryable_get_entity_connections)
13941401
// match writer and reader on a dummy topic
13951402
match_endpoints(false, "string", "test_topic_name");
13961403

1397-
auto participant_mock = static_cast<RTPSParticipantMock*>(participant_);
1398-
auto part_impl = participant_mock->get_impl();
1404+
eprosima::fastdds::rtps::RTPSParticipantImpl* part_impl = participant_->*get_rtps_part_impl();
13991405

14001406
part_impl->get_entity_connections(reader_->getGuid(), conns_reader);
14011407
part_impl->get_entity_connections(writer_->getGuid(), conns_writer);

0 commit comments

Comments
 (0)