Skip to content
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

Changed IPNetwork copy assignment implementation to copy-and-swap. #1681

Merged
merged 3 commits into from
Jan 9, 2025

Conversation

Dimi1010
Copy link
Collaborator

@Dimi1010 Dimi1010 commented Jan 5, 2025

This change fixes use of memory after being freed in case of self-assignment and provides a strong exception guarantee.

…he internal network.

This change fixes use of memory after being freed in case of self-assignment and provides a strong exception guarantee.
@Dimi1010 Dimi1010 requested a review from seladb as a code owner January 5, 2025 09:15
Copy link

codecov bot commented Jan 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.60%. Comparing base (91d2058) to head (3a987ca).
Report is 1 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1681      +/-   ##
==========================================
- Coverage   83.61%   83.60%   -0.01%     
==========================================
  Files         273      273              
  Lines       47565    47555      -10     
  Branches     9758     9789      +31     
==========================================
- Hits        39770    39757      -13     
- Misses       6926     6929       +3     
  Partials      869      869              
Flag Coverage Δ
alpine320 75.15% <ø> (-0.01%) ⬇️
fedora40 75.17% <ø> (+<0.01%) ⬆️
macos-13 80.65% <100.00%> (-0.01%) ⬇️
macos-14 80.65% <100.00%> (+<0.01%) ⬆️
macos-15 80.62% <100.00%> (-0.01%) ⬇️
mingw32 70.88% <ø> (-0.04%) ⬇️
mingw64 70.84% <ø> (-0.04%) ⬇️
npcap 85.28% <100.00%> (-0.03%) ⬇️
rhel94 75.03% <ø> (-0.02%) ⬇️
ubuntu2004 58.62% <ø> (-0.01%) ⬇️
ubuntu2004-zstd 58.71% <ø> (-0.01%) ⬇️
ubuntu2204 ?
ubuntu2204-icpx 61.38% <100.00%> (-0.02%) ⬇️
ubuntu2404 75.22% <ø> (-0.01%) ⬇️
unittest 83.60% <100.00%> (-0.01%) ⬇️
windows-2019 85.33% <100.00%> (-0.02%) ⬇️
windows-2022 85.35% <100.00%> (-0.02%) ⬇️
winpcap 85.32% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

m_IPv4Network = std::unique_ptr<IPv4Network>(new IPv4Network(other));

auto newNetwork = std::unique_ptr<IPv4Network>(new IPv4Network(other));
m_IPv4Network = std::move(newNetwork);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's necessary to use std::move here since a smart pointer is already cheap.
I would just use m_IPv4Network = std::unique_ptr<IPv4Network>(new IPv4Network(other)); for clearance.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the operations can be merged. Both should compile down to the same tho.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Dimi1010 I also think it will be the same after the compilation optimization. Then could you just merge the lines, so it looks cleaner?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be good now.

@tigercosmos
Copy link
Collaborator

Seems there is a CI failure, but should be unrelated.

@tigercosmos tigercosmos merged commit 6dd7c51 into seladb:dev Jan 9, 2025
39 of 40 checks passed
@Dimi1010 Dimi1010 deleted the fix/self-copy-warnings branch January 9, 2025 02:36
cla7aye15I4nd pushed a commit to aled-ua/PcapPlusPlus that referenced this pull request Jan 21, 2025
…eladb#1681)

* Changed `IPNetwork` copy assignment implementation to copy-and-swap the internal network.

This change fixes use of memory after being freed in case of self-assignment and provides a strong exception guarantee.

* Removed the temporary variable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants