Skip to content

main/php_ini.c: remove dead code #4512

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

Merged
merged 1 commit into from
Dec 10, 2022
Merged

Conversation

glensc
Copy link
Contributor

@glensc glensc commented Aug 11, 2019

main/php_ini.c:492 always initializes php_ini_search_path being empty:

php_ini_search_path[0] = 0;

That change was introduced in acb1e07 by @dstogov

@glensc glensc force-pushed the ini-dead-code branch 2 times, most recently from f41df19 to 93741a5 Compare August 11, 2019 13:10
@glensc
Copy link
Contributor Author

glensc commented Aug 11, 2019

NOTE: this patch was originally created from php-7.4.0beta2 tag, but as the bug is old as 5.2.0, should be merged to all active branches.

@dstogov @petk @derickr can you merge this for 7.4 and below? :)

@petk
Copy link
Member

petk commented Aug 11, 2019

cc @nikic I believe is the right ping here for the review. :) Merging dead code to PHP 7.4 is from my point of view still ok. Less diffs between 7.4 and 8.0 is very smart if we can do that.

@nikic
Copy link
Member

nikic commented Aug 11, 2019

It might make more sense to factor out this repetitive code-pattern into a function (append_ini_path or something).

@glensc
Copy link
Contributor Author

glensc commented Aug 11, 2019

@nikic exactly my idea. have some static method inside that same source file to avoid the repeative code.

@glensc
Copy link
Contributor Author

glensc commented Aug 11, 2019

ideally, I'd move those large platform-specific #ifdef blocks inside method also as separate static functions, then the main function is easier to follow.

@glensc glensc force-pushed the ini-dead-code branch 2 times, most recently from 86067f3 to f4ecfac Compare August 11, 2019 14:44
@glensc
Copy link
Contributor Author

glensc commented Aug 11, 2019

... added something

main/php_ini.c Outdated
return "";
}

size = GetEnvironmentVariableA(envname, phprc_path, size);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the size parameter should be min(size, MAXPATHLEN), not to overflow phprc_path.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nikic fix this or leave as is?

@nikic
Copy link
Member

nikic commented Aug 11, 2019

Appveyor:

main\php_ini.c(419): warning C4101: 'reg_location': unreferenced local variable
main\php_ini.c(524): error C2065: 'reg_location': undeclared identifier
main\php_ini.c(524): warning C4047: '=': 'int' differs in levels of indirection from 'char *'
main\php_ini.c(525): error C2065: 'reg_location': undeclared identifier
main\php_ini.c(525): warning C4047: '!=': 'int' differs in levels of indirection from 'void *'
main\php_ini.c(526): error C2065: 'reg_location': undeclared identifier
main\php_ini.c(526): warning C4047: 'function': 'char *' differs in levels of indirection from 'int'
main\php_ini.c(526): warning C4024: 'append_ini_path': different types for formal and actual parameter 3
main\php_ini.c(527): error C2065: 'reg_location': undeclared identifier
main\php_ini.c(527): warning C4022: '_efree': pointer mismatch for actual parameter 1
php_scandir.c

@glensc
Copy link
Contributor Author

glensc commented Aug 11, 2019

moved too much, fixed 62b362e

@glensc
Copy link
Contributor Author

glensc commented Aug 12, 2019

do you want me to rebase this to lowest branch? or maintainers can handle that? and in that case, what is that branch?

main/php_ini.c Outdated
return "";
}

env_location = phprc_path;
Copy link
Member

Choose a reason for hiding this comment

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

You are returning a reference to stack memory here. The pointer will be invalidated when the function returns.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

suggestions? always strdup value, return NULL if no value? playing with is_allocated variable seems overkill, as this code path is invoked only on init (not request init)?

Copy link
Member

Choose a reason for hiding this comment

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

One option would be to not return anything from get_env_location, but to pass the buffer into the function.

@ramsey
Copy link
Member

ramsey commented May 27, 2022

What's the status of this RFC? Is it still relevant? Should it target PHP-8.0?

@iluuu1994 iluuu1994 self-assigned this Dec 9, 2022
@iluuu1994 iluuu1994 merged commit e114f32 into php:master Dec 10, 2022
@glensc glensc deleted the ini-dead-code branch December 11, 2022 13:23
@glensc
Copy link
Contributor Author

glensc commented Dec 11, 2022

Only 3 years, 4 months to merge! thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants