]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-95355: Check tokens[0] after allocating memory (GH-95356)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 28 Jul 2022 10:45:01 +0000 (03:45 -0700)
committerGitHub <noreply@github.com>
Thu, 28 Jul 2022 10:45:01 +0000 (03:45 -0700)
GH-95355

Automerge-Triggered-By: GH:pablogsal
(cherry picked from commit b946f529efb4a623ac4ad968d8091edb81ebdcdb)

Co-authored-by: Honglin Zhu <zhuhonglin.zhl@alibaba-inc.com>
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 414059d12363cf4529ee0f0eaf79e22ce5759d8d..016f070c4745089d3c217736b0803e3b0d258742 100644 (file)
@@ -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();