[Python-checkins] gh-95355: Check tokens[0] after allocating memory (GH-95356)

miss-islington webhook-mailer at python.org
Thu Jul 28 06:45:05 EDT 2022


https://github.com/python/cpython/commit/4513e4aba8c38d6a6b51060e6697b8e4ce60c8c3
commit: 4513e4aba8c38d6a6b51060e6697b8e4ce60c8c3
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-07-28T03:45:01-07:00
summary:

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 at alibaba-inc.com>

files:
A Misc/NEWS.d/next/Core and Builtins/2022-07-28-08-33-31.gh-issue-95355.yN4XVk.rst
M Parser/pegen.c

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 0000000000000..6a289991e0d60
--- /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 414059d12363c..016f070c47450 100644
--- a/Parser/pegen.c
+++ b/Parser/pegen.c
@@ -1234,7 +1234,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();



More information about the Python-checkins mailing list