Skip to content

Uninitialized variable next_instr in error code path #128955

Closed
@colesbury

Description

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

Metadata

Assignees

Labels

3.14new features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)topic-free-threadingtype-bugAn unexpected behavior, bug, or error

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions