Skip to content

Fix EndPoint self-assignment - #3670

Open
songgaoye wants to merge 2 commits into
apache:masterfrom
songgaoye:fix-endpoint-self-assignment
Open

songgaoye wants to merge 2 commits into
apache:masterfrom
songgaoye:fix-endpoint-self-assignment

Conversation

@songgaoye

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: resolve

Problem Summary:

  • Self-assignment clears an EndPoint because reset() also modifies the source object.

What is changed and the side effects?

Changed:

  • Return early on self-assignment.
  • Add regression tests for IPv4, IPv6, and Unix socket addresses.

Side effects:

  • Performance effects: One pointer comparison per assignment.

  • Breaking backward compatibility: None.

  • Breaking backward compatibility:


Check List:

@chenBright
chenBright requested a lite review from Copilot October 26, 2026 13:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

3 open issues
What changed in this PR

Fixes butil::EndPoint self-assignment so it doesn’t accidentally clear extended endpoints (because reset() mutates shared state), and adds regression coverage for common address types.

Changes:

  • Add an early-return guard in EndPoint::operator= for this == &rhs.
  • Add a regression unit test covering self-assignment for IPv4, IPv6, and Unix socket endpoints.
File Description
test/​endpoint_unittest.cpp Adds a regression test to ensure self-assignment preserves endpoint value and extended storage.
src/​butil/​endpoint.cpp Prevents reset() from running on self-assignment by adding an early return.

Review effort: Lite

Comment thread test/endpoint_unittest.cpp Outdated
Comment thread test/endpoint_unittest.cpp Outdated
Comment thread test/endpoint_unittest.cpp Outdated
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