]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-95355: Check tokens[0] after allocating memory (GH-95356)
authorHonglin Zhu <zhuhonglin.zhl@alibaba-inc.com>
Thu, 28 Jul 2022 10:00:34 +0000 (18:00 +0800)
committerGitHub <noreply@github.com>
Thu, 28 Jul 2022 10:00:34 +0000 (03:00 -0700)
#95355

Automerge-Triggered-By: GH:pablogsal
Misc/NEWS.d/next/Core and Builtins/2022-07-28-08-33-31.gh-issue-95355.yN4XVk.rst [new file with mode: 0644]
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 (file)
index 0000000..6a28999
--- /dev/null
@@ -0,0 +1 @@
+``_PyPegen_Parser_New`` now properly detects token memory allocation errors. Patch by Honglin Zhu.
index dbf105aedcf427a464482bdc5d3421a97d36847d..31e3ec05a105304b7e6244b55ff3437be342deb1 100644 (file)
@@ -738,7 +738,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();