Skip to content

Fix socket_export_stream() with wrong proto #12310

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

Closed
wants to merge 1 commit into from

Conversation

twose
Copy link
Member

@twose twose commented Sep 27, 2023

before

image

after

image

@twose twose requested a review from devnexen September 27, 2023 18:27
@@ -2315,7 +2310,7 @@ PHP_FUNCTION(socket_export_stream)
* We don't want streams to actually *do* anything though, so don't give it
* anything apart from the protocol */
if (protocol != NULL) {
stream = php_stream_xport_create(protocol, protocollen, 0, 0, NULL, NULL, NULL, NULL, NULL);
stream = php_stream_xport_create(protocol, strlen(protocol), 0, 0, NULL, NULL, NULL, NULL, NULL);
Copy link
Member

Choose a reason for hiding this comment

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

IMHO keeping the variable makes sense, as the compiler can elide the call to strlen() when the value is constant.

Copy link
Member Author

@twose twose Sep 28, 2023

Choose a reason for hiding this comment

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

This function is inherently "heavy", and it's not a high-frequency operation, the calculation of the text length of the protocol isn't a key factor affecting performance. Therefore, I have no preference for the way of calculation. In the new commit, I've added a const modifier to the protocol to avoid generating compile warnings and used sizeof(protocol - 1) to enhance readability and 100% ensure that it would be comfortable in terms of performance.

@twose twose force-pushed the fix_export_proto_8_1 branch from a32368e to 08ee346 Compare September 28, 2023 10:00
@nielsdos nielsdos assigned nielsdos and unassigned nielsdos Sep 28, 2023
@twose twose closed this in b5da98b Sep 29, 2023
@twose twose deleted the fix_export_proto_8_1 branch September 29, 2023 11:01
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.

4 participants