Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d951e7b

Browse files
committed
check the return value of NEW_IDENTIFIER in some more places
1 parent 45dea65 commit d951e7b

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

Python/ast.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ static int
654654
handle_keywordonly_args(struct compiling *c, const node *n, int start,
655655
asdl_seq *kwonlyargs, asdl_seq *kwdefaults)
656656
{
657+
PyObject *argname;
657658
node *ch;
658659
expr_ty expression, annotation;
659660
arg_ty arg;
@@ -690,11 +691,12 @@ handle_keywordonly_args(struct compiling *c, const node *n, int start,
690691
annotation = NULL;
691692
}
692693
ch = CHILD(ch, 0);
693-
arg = arg(NEW_IDENTIFIER(ch), annotation, c->c_arena);
694-
if (!arg) {
695-
ast_error(ch, "expecting name");
694+
argname = NEW_IDENTIFIER(ch);
695+
if (!argname)
696+
goto error;
697+
arg = arg(argname, annotation, c->c_arena);
698+
if (!arg)
696699
goto error;
697-
}
698700
asdl_seq_SET(kwonlyargs, j++, arg);
699701
i += 2; /* the name and the comma */
700702
break;
@@ -3000,7 +3002,7 @@ ast_for_classdef(struct compiling *c, const node *n, asdl_seq *decorator_seq)
30003002
/* classdef: 'class' NAME ['(' arglist ')'] ':' suite */
30013003
PyObject *classname;
30023004
asdl_seq *s;
3003-
expr_ty call, dummy;
3005+
expr_ty call;
30043006

30053007
REQ(n, classdef);
30063008

@@ -3028,10 +3030,17 @@ ast_for_classdef(struct compiling *c, const node *n, asdl_seq *decorator_seq)
30283030

30293031
/* class NAME '(' arglist ')' ':' suite */
30303032
/* build up a fake Call node so we can extract its pieces */
3031-
dummy = Name(NEW_IDENTIFIER(CHILD(n, 1)), Load, LINENO(n), n->n_col_offset, c->c_arena);
3032-
call = ast_for_call(c, CHILD(n, 3), dummy);
3033-
if (!call)
3034-
return NULL;
3033+
{
3034+
PyObject *dummy_name;
3035+
expr_ty dummy;
3036+
dummy_name = NEW_IDENTIFIER(CHILD(n, 1));
3037+
if (!dummy_name)
3038+
return NULL;
3039+
dummy = Name(dummy_name, Load, LINENO(n), n->n_col_offset, c->c_arena);
3040+
call = ast_for_call(c, CHILD(n, 3), dummy);
3041+
if (!call)
3042+
return NULL;
3043+
}
30353044
s = ast_for_suite(c, CHILD(n, 6));
30363045
if (!s)
30373046
return NULL;

0 commit comments

Comments
 (0)