Skip to content

Commit 4513e4a

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 <[email protected]>
1 parent dcb6fa8 commit 4513e4a

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
@@ -1234,7 +1234,7 @@ _PyPegen_Parser_New(struct tok_state *tok, int start_rule, int flags,
12341234
return (Parser *) PyErr_NoMemory();
12351235
}
12361236
p->tokens[0] = PyMem_Calloc(1, sizeof(Token));
1237-
if (!p->tokens) {
1237+
if (!p->tokens[0]) {
12381238
PyMem_Free(p->tokens);
12391239
PyMem_Free(p);
12401240
return (Parser *) PyErr_NoMemory();

0 commit comments

Comments
 (0)