Skip to content

Commit b946f52

Browse files
authored
gh-95355: Check tokens[0] after allocating memory (GH-95356)
#95355 Automerge-Triggered-By: GH:pablogsal
1 parent e16d4ed commit b946f52

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
@@ -738,7 +738,7 @@ _PyPegen_Parser_New(struct tok_state *tok, int start_rule, int flags,
738738
return (Parser *) PyErr_NoMemory();
739739
}
740740
p->tokens[0] = PyMem_Calloc(1, sizeof(Token));
741-
if (!p->tokens) {
741+
if (!p->tokens[0]) {
742742
PyMem_Free(p->tokens);
743743
PyMem_Free(p);
744744
return (Parser *) PyErr_NoMemory();

0 commit comments

Comments
 (0)