8000 gh-95355: Check tokens[0] after allocating memory (GH-95356) · python/cpython@d3cc99b · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit d3cc99b

Browse files
gh-95355: Check tokens[0] after allocating memory (GH-95356)
GH-95355 Automerge-Triggered-By: GH:pablogsal (cherry picked from commit b946f52) Co-authored-by: Honglin Zhu <zhuhonglin.zhl@alibaba-inc.com>
1 parent 7813d97 commit d3cc99b

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``_PyPegen_Parser_New`` now properly detects token memory allocation errors. Patch by Honglin Zhu.

Parser/pegen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ _PyPegen_Parser_New(struct tok_state *tok, int start_rule, int flags,
744744
return (Parser *) PyErr_NoMemory();
745745
}
746746
p->tokens[0] = PyMem_Calloc(1, sizeof(Token));
747-
if (!p->tokens) {
747+
if (!p->tokens[0]) {
748748
PyMem_Free(p->tokens);
749749
PyMem_Free(p);
750750
return (Parser *) PyErr_NoMemory();

0 commit comments

Comments
 (0)
0