-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Completely unnecessary compiler warnings in function ‘from_zval_write_sockaddr_aux’ #10959
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
Comments
I'm not hitting those bogus compiler warnings on Fedora 37 and GCC 12.2.1 nor Clang 15. What is the full GCC compiler version you are running? |
|
I think the warnings are true positives. |
This was first pointed out in phpGH-10959. The from_zval_... functions don't always write to the pointer, in particular it is necessary to check for an error before using the value. Otherwise we can access an uninitialized value and that's UB (and dangerous). Note: this does *NOT* get rid of the compiler warning. Even though there is error checking now, the compiler isn't smart enough to figure out that the values can not be used uninitialized.
I submitted a PR to fix the uninitialized accesses. However, this does not get rid of the compile warnings because now the compiler is just not smart enough to see the variables can no longer be used uninitialized. |
I understand, but don't you think that just a dummy initialisation - while the declaration - should be done, just to get rid of the warning? It's always good to have no warning even you know the compiler isn't smart enough to analyse the flow correctly? |
IMO yes we should get rid of the warning, I was already considering that. I also read the review comment on my PR now and proposed a solution for the warning: #10966 (comment). |
OK, I now checked the function Now, the situation changed and I don't think that the compiler can see that the added code fixed a bug and now indeed the variable cannot be accessed uninitialised - due to the new check. Maybe gcc 16 is that smart but there remains always the problem that the function is in another file, so the compiler doesn't have enough information. A conditional meta data informing the compiler when the variable is written could solve the problem but this is something for the future... |
This was first pointed out in GH-10959. The from_zval_... functions don't always write to the pointer, in particular it is necessary to check for an error before using the value. Otherwise we can access an uninitialized value and that's UB (and dangerous). Note: this does *NOT* get rid of the compiler warning. Even though there is error checking now, the compiler isn't smart enough to figure out that the values can not be used uninitialized. Closes GH-10966.
These values will be initialised, but the compiler can't see it. Write a dummy value to silence this. Closes phpGH-10959.
These values will be initialised, but the compiler can't see it. Write a dummy value to silence this. Closes GH-10959.
The text was updated successfully, but these errors were encountered: