Skip to content

Add const modifier for zend_extension #6462

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

Conversation

huanghantao
Copy link
Contributor

@huanghantao huanghantao commented Nov 27, 2020

There are some compile warning

@nikic
Copy link
Member

nikic commented Nov 27, 2020

/home/vsts/work/1/s/sapi/phpdbg/phpdbg_prompt.c: In function ‘phpdbg_load_module_or_extension’:
/home/vsts/work/1/s/sapi/phpdbg/phpdbg_prompt.c:1297:9: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
 1297 |   *name = new_extension->name;
      |         ^

@@ -1386,7 +1386,7 @@ PHPDBG_COMMAND(dl) /* {{{ */
path = estrndup(param->str, param->len);

phpdbg_activate_err_buf(1);
if ((type = phpdbg_load_module_or_extension(&path, &name)) == NULL) {
if ((type = phpdbg_load_module_or_extension(&path, (const char **) &name)) == NULL) {
Copy link
Member

@nikic nikic Nov 30, 2020

Choose a reason for hiding this comment

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

Heh, we're nearly there! Now, changing char *name to const char *name in the variable declaration above should allow us to avoid casts completely if I see it right.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Heh, we're nearly there! Now, changing char *name to const char *name in the variable declaration above should allow us to avoid casts completely if I see it right.

ha, but we should convert efree(name);:

/Users/hantaohuang/codeDir/cCode/php-src/sapi/phpdbg/phpdbg_prompt.c:1391:5: warning: passing 'const char *' to parameter of type 'void *' discards qualifiers
      [-Wincompatible-pointer-types-discards-qualifiers]
                                efree(name);

Copy link
Member

Choose a reason for hiding this comment

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

I think this call to efree is actually a bug. The name should not be freed. (It also looks like the whole dl command is effectively dead code right now, because it's not exposed to users.)

So I think you can simply drop this call.

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