Skip to content
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

Uninitialized variable next_instr in error code path #128955

Closed
colesbury opened this issue Jan 17, 2025 · 0 comments
Closed

Uninitialized variable next_instr in error code path #128955

colesbury opened this issue Jan 17, 2025 · 0 comments
Assignees
Labels
3.14 new features, bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-free-threading type-bug An unexpected behavior, bug, or error

Comments

@colesbury
Copy link
Contributor

colesbury commented Jan 17, 2025

Bug report

cpython/Python/ceval.c

Lines 843 to 855 in d95ba9f

#ifdef Py_GIL_DISABLED
/* Load thread-local bytecode */
if (frame->tlbc_index != ((_PyThreadStateImpl *)tstate)->tlbc_index) {
_Py_CODEUNIT *bytecode =
_PyEval_GetExecutableCode(tstate, _PyFrame_GetCode(frame));
if (bytecode == NULL) {
goto error;
}
ptrdiff_t off = frame->instr_ptr - _PyFrame_GetBytecode(frame);
frame->tlbc_index = ((_PyThreadStateImpl *)tstate)->tlbc_index;
frame->instr_ptr = bytecode + off;
}
#endif

Clang warns:

Python/ceval.c:848:17: warning: variable 'next_instr' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
  848 |             if (bytecode == NULL) {
      |                 ^~~~~~~~~~~~~~~~
Python/ceval.c:957:45: note: uninitialized use occurs here
  957 |         _PyEval_MonitorRaise(tstate, frame, next_instr-1);
      |                                             ^~~~~~~~~~
Python/ceval.c:848:13: note: remove the 'if' if its condition is always false
  848 |             if (bytecode == NULL) {
      |             ^~~~~~~~~~~~~~~~~~~~~~~
  849 |                 goto error;
      |                 ~~~~~~~~~~~
  850 |             }
      |             ~

The warning looks legitimate to me. Nearby code mostly uses goto exit_unwind. Maybe we should use that instead of goto error?

cc @mpage

Linked PRs

@colesbury colesbury added 3.14 new features, bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-free-threading type-bug An unexpected behavior, bug, or error labels Jan 17, 2025
@mpage mpage self-assigned this Jan 17, 2025
mpage added a commit that referenced this issue Jan 17, 2025
…ator (#128957)

We don't have the correct copy of the bytecode and can't update next_instr
appropriately, so just unwind.
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this issue Jan 21, 2025
… generator (python#128957)

We don't have the correct copy of the bytecode and can't update next_instr
appropriately, so just unwind.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.14 new features, bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-free-threading type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants