Skip to content

gh-112301: fix compiler warning about a possible use of an uninitialized variable#112308

Closed
carsonRadtke wants to merge 1 commit intopython:mainfrom
carsonRadtke:cradtke/fix-maybe-uninit-build-warning
Closed

gh-112301: fix compiler warning about a possible use of an uninitialized variable#112308
carsonRadtke wants to merge 1 commit intopython:mainfrom
carsonRadtke:cradtke/fix-maybe-uninit-build-warning

Conversation

@carsonRadtke
Copy link
Copy Markdown
Contributor

@carsonRadtke carsonRadtke commented Nov 22, 2023

In #112301, @mdboom posted a proposal for adding some recommended compiler flags.

This PR addresses a single class of warnings (-Wmaybe-uninitialized) that may crop up if we were to switch to the "hardened" build command.

Specific build error:

./Modules/_io/fileio.c:175:9: warning: ‘exc’ may be used uninitialized [-Wmaybe-uninitialized]
  175 |         _PyErr_ChainExceptions1(exc);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Modules/_io/fileio.c: In function ‘_io_FileIO_close’:
./Modules/_io/fileio.c:160:15: note: ‘exc’ was declared here
  160 |     PyObject *exc;

@ghost
Copy link
Copy Markdown

ghost commented Nov 22, 2023

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Nov 22, 2023

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@sethmlarson
Copy link
Copy Markdown
Contributor

Should we be adding the -Wmaybe-uninitialized option to the build in this PR as well? I think that's coming from -Wall but it's unlikely we enable that option in particular?

@mdboom
Copy link
Copy Markdown
Contributor

mdboom commented Nov 22, 2023

Should we be adding the -Wmaybe-uninitialized option to the build in this PR as well? I think that's coming from -Wall but it's unlikely we enable that option in particular?

Alternatively, should we be adding -Werror=maybe-uninitialized which would error if this kind of thing ever crept back in? IMHO, warnings almost always just get ignored. I'm pretty comfortable that this warning is just a bunch of false positives that are hard to fix. On the other hand, we should probably build consensus before adding new error types. (Probably a discussion to have in the general sense over on #112301).

@vstinner
Copy link
Copy Markdown
Member

The PyObject *exc = NULL; code was fixed by another change in the meanwhile: commit 05e4720.

I'm not sure that replacing if (res == NULL) { with if (exc != NULL) { is correct. IMO the current code is fine.

I close this PR since it's inactive since 2023: #112301 (comment).

@vstinner vstinner closed this Mar 26, 2026
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