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

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

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.15%. Comparing base (7898a5d) to head (0ac8f92).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1681      +/-   ##
==========================================
- Coverage   83.16%   83.15%   -0.01%     
==========================================
  Files         277      277              
  Lines       48201    48192       -9     
  Branches     9932     9941       +9     
==========================================
- Hits        40086    40075      -11     
+ Misses       7266     7242      -24     
- Partials      849      875      +26     
Flag Coverage Δ
alpine320 75.15% <100.00%> (-0.01%) ⬇️
fedora40 75.17% <100.00%> (+<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% <100.00%> (-0.04%) ⬇️
mingw64 70.84% <100.00%> (-0.04%) ⬇️
npcap 85.30% <100.00%> (-0.02%) ⬇️
rhel94 75.03% <100.00%> (+<0.01%) ⬆️
ubuntu2004 58.62% <100.00%> (-0.02%) ⬇️
ubuntu2004-zstd 58.74% <100.00%> (+0.01%) ⬆️
ubuntu2204 74.94% <100.00%> (-0.03%) ⬇️
ubuntu2204-icpx 61.42% <100.00%> (-0.02%) ⬇️
ubuntu2404 75.19% <100.00%> (-0.03%) ⬇️
unittest 83.15% <100.00%> (-0.01%) ⬇️
windows-2019 85.33% <100.00%> (-0.02%) ⬇️
windows-2022 85.36% <100.00%> (-0.02%) ⬇️
winpcap 85.32% <100.00%> (-0.01%) ⬇️
xdp 50.53% <0.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.

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