diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-07-28 10:29:50 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-28 10:29:50 (GMT) |
commit | d3cc99bdce269ff8836bee9fc6f6c275b42a5152 (patch) | |
tree | e94b4c1654396967535522c707061f2123d57264 | |
parent | 7813d976aeaabea0a232f3c782e4fc25fe93a27d (diff) | |
download | cpython-d3cc99bdce269ff8836bee9fc6f6c275b42a5152.zip cpython-d3cc99bdce269ff8836bee9fc6f6c275b42a5152.tar.gz cpython-d3cc99bdce269ff8836bee9fc6f6c275b42a5152.tar.bz2 |
gh-95355: Check tokens[0] after allocating memory (GH-95356)
GH-95355
Automerge-Triggered-By: GH:pablogsal
(cherry picked from commit b946f529efb4a623ac4ad968d8091edb81ebdcdb)
Co-authored-by: Honglin Zhu <zhuhonglin.zhl@alibaba-inc.com>
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2022-07-28-08-33-31.gh-issue-95355.yN4XVk.rst | 1 | ||||
-rw-r--r-- | Parser/pegen.c | 2 |
2 files changed, 2 insertions, 1 deletions
diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-07-28-08-33-31.gh-issue-95355.yN4XVk.rst b/Misc/NEWS.d/next/Core and Builtins/2022-07-28-08-33-31.gh-issue-95355.yN4XVk.rst new file mode 100644 index 0000000..6a28999 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-07-28-08-33-31.gh-issue-95355.yN4XVk.rst @@ -0,0 +1 @@ +``_PyPegen_Parser_New`` now properly detects token memory allocation errors. Patch by Honglin Zhu. diff --git a/Parser/pegen.c b/Parser/pegen.c index 143461d..e093de3 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -744,7 +744,7 @@ _PyPegen_Parser_New(struct tok_state *tok, int start_rule, int flags, return (Parser *) PyErr_NoMemory(); } p->tokens[0] = PyMem_Calloc(1, sizeof(Token)); - if (!p->tokens) { + if (!p->tokens[0]) { PyMem_Free(p->tokens); PyMem_Free(p); return (Parser *) PyErr_NoMemory(); |