Skip to content

Fixed Ip::Address copying#126

Merged
yadij merged 2 commits intosquid-cache:masterfrom
yadij:v5-cleanup_ip_memcpy
Jan 20, 2018
Merged

Fixed Ip::Address copying#126
yadij merged 2 commits intosquid-cache:masterfrom
yadij:v5-cleanup_ip_memcpy

Conversation

@yadij
Copy link
Contributor

@yadij yadij commented Jan 15, 2018

Explicit copy construction was slow and unnecessary.
Explicit copy assignment mishandled self copying and was unnecessary.
The remaining memcpy() calls mishandled self copying.

There are no known cases of Ip::Address self copying.

@yadij yadij force-pushed the v5-cleanup_ip_memcpy branch from f01d48e to f521fd4 Compare January 15, 2018 13:32
Ip::Address::operator =(const Ip::Address &s)
{
memcpy(this, &s, sizeof(Ip::Address));
memmove(&mSocketAddr_, &s.mSocketAddr_, sizeof(struct sockaddr_in6));
Copy link
Contributor

Choose a reason for hiding this comment

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

If the default generated assignment operator works, please use that instead (and check whether we can remove an explicit copy constructor as well).

@yadij
Copy link
Contributor Author

yadij commented Jan 15, 2018

Do you mean converting those two to their C++11 " = default;" definitions?

@rousskov
Copy link
Contributor

Yes, either that or removing them completely. If both solutions "work", pick whichever style you prefer for this use case (explicit =default or nothing explicit at all).

@yadij yadij force-pushed the v5-cleanup_ip_memcpy branch from f521fd4 to 223d7d6 Compare January 15, 2018 21:42
@yadij yadij added the S-waiting-for-reviewer ready for review: Set this when requesting a (re)review using GitHub PR Reviewers box label Jan 16, 2018
@rousskov rousskov changed the title Fix many incorrect uses of memcpy in IP::Address Fixed IP::Address copying Jan 19, 2018
@rousskov rousskov changed the title Fixed IP::Address copying Fixed Ip::Address copying Jan 19, 2018
Copy link
Contributor

@rousskov rousskov left a comment

Choose a reason for hiding this comment

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

LGTM.

I polished the PR (and future commit) title and description to match the latest code version, to fix namespace spelling, and to disclaim knowledge of any specific bugs this fix addresses (AFAIK). Please feel free to polish further as needed and do not forget to use the updated title/description during the commit.

@rousskov rousskov added S-waiting-for-committer privileged action is expected (and usually required) and removed S-waiting-for-reviewer ready for review: Set this when requesting a (re)review using GitHub PR Reviewers box labels Jan 19, 2018
yadij added 2 commits January 20, 2018 03:15
Most uses of memcpy should have been memove() to prevent potential copy-to-self bugs.
The default copy-construct and copy-assignment operators seem sufficient
and under C++11 now seem to work.
@yadij yadij force-pushed the v5-cleanup_ip_memcpy branch from 223d7d6 to 9b9da2e Compare January 19, 2018 14:16
@yadij yadij merged commit 9f15dc4 into squid-cache:master Jan 20, 2018
@yadij yadij deleted the v5-cleanup_ip_memcpy branch January 20, 2018 04:54
squidadm pushed a commit to squidadm/squid that referenced this pull request Feb 1, 2018
Explicit copy construction was slow and unnecessary.
Explicit copy assignment mishandled self copying and was unnecessary.
The remaining memcpy() calls mishandled self copying.

There are no known cases of Ip::Address self copying.
yadij added a commit that referenced this pull request Feb 2, 2018
Explicit copy construction was slow and unnecessary.
Explicit copy assignment mishandled self copying and was unnecessary.
The remaining memcpy() calls mishandled self copying.

There are no known cases of Ip::Address self copying.
squidadm pushed a commit to squidadm/squid that referenced this pull request Jul 8, 2018
Explicit copy construction was slow and unnecessary.
Explicit copy assignment mishandled self copying and was unnecessary.
The remaining memcpy() calls mishandled self copying.

There are no known cases of Ip::Address self copying.
squidadm pushed a commit to squidadm/squid that referenced this pull request Jul 8, 2018
Explicit copy construction was slow and unnecessary.
Explicit copy assignment mishandled self copying and was unnecessary.
The remaining memcpy() calls mishandled self copying.

There are no known cases of Ip::Address self copying.
yadij added a commit that referenced this pull request Jul 8, 2018
Explicit copy construction was slow and unnecessary.
Explicit copy assignment mishandled self copying and was unnecessary.
The remaining memcpy() calls mishandled self copying.

There are no known cases of Ip::Address self copying.
@rousskov rousskov removed the S-waiting-for-committer privileged action is expected (and usually required) label Jul 22, 2023
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.

2 participants