mirror of
https://github.com/python/cpython.git
synced 2025-09-09 18:32:22 +00:00
Fix a SystemError in code.replace() (#27771)
While the comment said 'We don't bother resizing localspluskinds', this would cause .replace() to crash when it happened. (Also types.CodeType(), but testing that is tedious, and this tests all code paths.)
This commit is contained in:
parent
a0a6d39295
commit
62bd97303e
2 changed files with 14 additions and 3 deletions
|
@ -471,9 +471,11 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount,
|
|||
localsplusnames, localspluskinds);
|
||||
}
|
||||
// If any cells were args then nlocalsplus will have shrunk.
|
||||
// We don't bother resizing localspluskinds.
|
||||
if (_PyTuple_Resize(&localsplusnames, nlocalsplus) < 0) {
|
||||
goto error;
|
||||
if (nlocalsplus != PyTuple_GET_SIZE(localsplusnames)) {
|
||||
if (_PyTuple_Resize(&localsplusnames, nlocalsplus) < 0
|
||||
|| _PyBytes_Resize(&localspluskinds, nlocalsplus) < 0) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
struct _PyCodeConstructor con = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue