Skip to content

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Apr 5, 2019

Initialize init_utf8_mode earlier to fix a compiler warning.

https://bugs.python.org/issue36301

Initialize init_utf8_mode earlier to fix a compiler warning.
@vstinner
Copy link
Member Author

vstinner commented Apr 5, 2019

Example of warning seen on PR #12661:

https://dev.azure.com/Python/cpython/_build/results?buildId=40348

Python/preconfig.c:725:13: warning: variable 'init_utf8_mode' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
        if (_Py_INIT_FAILED(err)) {
            ^~~~~~~~~~~~~~~~~~~~
./Include/cpython/coreconfig.h:37:5: note: expanded from macro '_Py_INIT_FAILED'
    (err.msg != NULL || err.exitcode != -1)
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Python/preconfig.c:815:19: note: uninitialized use occurs here
    Py_UTF8Mode = init_utf8_mode ;
                  ^~~~~~~~~~~~~~
Python/preconfig.c:725:9: note: remove the 'if' if its condition is always false
        if (_Py_INIT_FAILED(err)) {
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
Python/preconfig.c:725:29: warning: variable 'init_utf8_mode' is used uninitialized whenever '||' condition is true [-Wsometimes-uninitialized]
        if (_Py_INIT_FAILED(err)) {
            ~~~~~~~~~~~~~~~~^~~~
./Include/cpython/coreconfig.h:37:6: note: expanded from macro '_Py_INIT_FAILED'
    (err.msg != NULL || err.exitcode != -1)
     ^~~~~~~~~~~~~~~
Python/preconfig.c:815:19: note: uninitialized use occurs here
    Py_UTF8Mode = init_utf8_mode ;
                  ^~~~~~~~~~~~~~
Python/preconfig.c:725:29: note: remove the '||' if its condition is always false
        if (_Py_INIT_FAILED(err)) {
                            ^
Python/preconfig.c:730:5: note: variable 'init_utf8_mode' is declared here
    int init_utf8_mode = Py_UTF8Mode;
    ^
2 warnings generated.

@tirkarthi
Copy link
Member

See also #12644 . Does this PR also fix the same issue ?

@vstinner vstinner merged commit 6a8c313 into python:master Apr 5, 2019
@vstinner vstinner deleted the preconfig_fix_warn branch April 5, 2019 09:44
@vstinner
Copy link
Member Author

vstinner commented Apr 5, 2019

See also #12644 . Does this PR also fix the same issue ?

Thanks. I missed this PR, thanks for the pointer. I closed this PR as well.

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.

4 participants