iceoryx
iceoryx copied to clipboard
Undefined behavior in all classes with `getMembers` method
Required information
Nearly all classes with the method getMembers()
have undefined behavior after move since the move constructor and assignment operator have default specifiers which do not invalidate the underlying data pointer.
(Maybe incomplete list) of all affected classes
- InterfacePort
- ServerPortUser
- PublisherPortUser
- PublisherPortRoudi
- ServerPortRoudi
- ApplicationPort
- SubscriberPortUser
- ClientPortUser
- ClientPortRoudi
- BasePort
- ChunkQueuePopper
- ChunkSender
- ChunkQueuePusher
- ChunkReceiver
- ConditionListener
- ConditionNotifier
- ChunkDistributor
Solution
- For every class an explicit move constructor and move assignment operator has to be implemented which invalidates the pointer to the members. But please pay attention to call the parent move constructor/assignment operator first when there is inheritance involved!
Parent::operator=(std::move(*this));
-
getMembers
must return a reference/const reference to the underlying members since the members should be nevernullptr
.
Maybe we should think of using something like the std::reference_wrapper
instead of implementing all the move constructors and assignment operators in the classes itself. The only problem is that the classes are not memcopyable anymore. Not sure if they are now or if it's important.