-
Notifications
You must be signed in to change notification settings - Fork 652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes PointerVector's slicing issue for polymorphic types. #1550
Conversation
- Adds a clone method that is enabled when the held type is non-polymorphic or contains a clone method. - Deprecates the copy constructor and copy assignment operator.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #1550 +/- ##
==========================================
- Coverage 82.94% 82.89% -0.05%
==========================================
Files 273 273
Lines 46353 46265 -88
Branches 9642 9387 -255
==========================================
- Hits 38446 38351 -95
+ Misses 7280 7057 -223
- Partials 627 857 +230
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Hmm, upon further thoughts, the |
@@ -343,21 +372,16 @@ namespace pcpp | |||
static std::vector<T*> deepCopyUnsafe(std::vector<T*> const& origin) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can change the method name to just deepCopy()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is specifically named unsafe as the returned vector contains allocated objects that need to be manually freed by the caller. same with freeVectorUnsafe
where the pointers in the vector refer to invalid values after the function return.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small comment, otherwise LGTM!
Packet++/header/RawPacket.h
Outdated
@@ -1,6 +1,7 @@ | |||
#pragma once | |||
|
|||
#include <stdint.h> | |||
#include <memory> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this include needed? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its not. It's left over from when I was prototyping the clone method as i was initially thinking of using unique_ptr but that had issues with unique pointers of Derived types not being covariant of unique pointers to base types.
* Fixes PointerVector's slicing issue for polymorphic types. - Adds a clone method that is enabled when the held type is non-polymorphic or contains a clone method. - Deprecates the copy constructor and copy assignment operator. * Fixed usages of post C++11 symbols. * Updated PointerVector to use Copier helper struct to facilitate a copy mechanism. * Added clone to RawPacket as it is polymorphic. * Remove unused include.
Fixes #1549
clone()
member function.NB: A valid
T::clone()
method can return either aT*
or astd::unique_ptr<T>
.An demo of the changes: