Skip to content

Commit 8d294e7

Browse files
author
benjamin.peterson
committed
Merged revisions 67373 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r67373 | benjamin.peterson | 2008-11-24 21:43:14 -0600 (Mon, 24 Nov 2008) | 2 lines always check the return value of NEW_IDENTIFIER ........ git-svn-id: http://svn.python.org/projects/python/branches/py3k@67375 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 4e95c89 commit 8d294e7

1 file changed

Lines changed: 47 additions & 15 deletions

File tree

Python/ast.c

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ static identifier
5151
new_identifier(const char* n, PyArena *arena)
5252
{
5353
PyObject* id = PyUnicode_DecodeUTF8(n, strlen(n), NULL);
54+
if (!id)
55+
return NULL;
5456
Py_UNICODE *u = PyUnicode_AS_UNICODE(id);
5557
/* Check whether there are non-ASCII characters in the
5658
identifier; if so, normalize to NFKC. */
@@ -826,7 +828,6 @@ ast_for_arguments(struct compiling *c, const node *n)
826828
if (!arg)
827829
goto error;
828830
asdl_seq_SET(posargs, k++, arg);
829-
830831
i += 2; /* the name and the comma */
831832
break;
832833
case STAR:
@@ -846,6 +847,8 @@ ast_for_arguments(struct compiling *c, const node *n)
846847
}
847848
else {
848849
vararg = NEW_IDENTIFIER(CHILD(ch, 0));
850+
if (!vararg)
851+
return NULL;
849852
if (NCH(ch) > 1) {
850853
/* there is an annotation on the vararg */
851854
varargannotation = ast_for_expr(c, CHILD(ch, 2));
@@ -869,6 +872,8 @@ ast_for_arguments(struct compiling *c, const node *n)
869872
/* there is an annotation on the kwarg */
870873
kwargannotation = ast_for_expr(c, CHILD(ch, 2));
871874
}
875+
if (!kwarg)
876+
goto error;
872877
i += 3;
873878
break;
874879
default:
@@ -1311,10 +1316,14 @@ ast_for_atom(struct compiling *c, const node *n)
13111316
int bytesmode = 0;
13121317

13131318
switch (TYPE(ch)) {
1314-
case NAME:
1319+
case NAME: {
13151320
/* All names start in Load context, but may later be
13161321
changed. */
1317-
return Name(NEW_IDENTIFIER(ch), Load, LINENO(n), n->n_col_offset, c->c_arena);
1322+
PyObject *name = NEW_IDENTIFIER(ch);
1323+
if (!name)
1324+
return NULL;
1325+
return Name(name, Load, LINENO(n), n->n_col_offset, c->c_arena);
1326+
}
13181327
case STRING: {
13191328
PyObject *str = parsestrplus(c, n, &bytesmode);
13201329
if (!str) {
@@ -1589,7 +1598,10 @@ ast_for_trailer(struct compiling *c, const node *n, expr_ty left_expr)
15891598
return ast_for_call(c, CHILD(n, 1), left_expr);
15901599
}
15911600
else if (TYPE(CHILD(n, 0)) == DOT ) {
1592-
return Attribute(left_expr, NEW_IDENTIFIER(CHILD(n, 1)), Load,
1601+
PyObject *attr_id = NEW_IDENTIFIER(CHILD(n, 1));
1602+
if (!attr_id)
1603+
return NULL;
1604+
return Attribute(left_expr, attr_id, Load,
15931605
LINENO(n), n->n_col_offset, c->c_arena);
15941606
}
15951607
else {
@@ -2275,16 +2287,21 @@ alias_for_import_name(struct compiling *c, const node *n)
22752287
dotted_as_name: dotted_name ['as' NAME]
22762288
dotted_name: NAME ('.' NAME)*
22772289
*/
2278-
PyObject *str;
2290+
PyObject *str, *name;
22792291

22802292
loop:
22812293
switch (TYPE(n)) {
22822294
case import_as_name:
22832295
str = NULL;
22842296
if (NCH(n) == 3) {
22852297
str = NEW_IDENTIFIER(CHILD(n, 2));
2298+
if (!str)
2299+
return NULL;
22862300
}
2287-
return alias(NEW_IDENTIFIER(CHILD(n, 0)), str, c->c_arena);
2301+
name = NEW_IDENTIFIER(CHILD(n, 0));
2302+
if (!name)
2303+
return NULL;
2304+
return alias(name, str, c->c_arena);
22882305
case dotted_as_name:
22892306
if (NCH(n) == 1) {
22902307
n = CHILD(n, 0);
@@ -2296,12 +2313,18 @@ alias_for_import_name(struct compiling *c, const node *n)
22962313
return NULL;
22972314
assert(!a->asname);
22982315
a->asname = NEW_IDENTIFIER(CHILD(n, 2));
2316+
if (!a->asname)
2317+
return NULL;
22992318
return a;
23002319
}
23012320
break;
23022321
case dotted_name:
2303-
if (NCH(n) == 1)
2304-
return alias(NEW_IDENTIFIER(CHILD(n, 0)), NULL, c->c_arena);
2322+
if (NCH(n) == 1) {
2323+
name = NEW_IDENTIFIER(CHILD(n, 0));
2324+
if (!name)
2325+
return NULL;
2326+
return alias(name, NULL, c->c_arena);
2327+
}
23052328
else {
23062329
/* Create a string of the form "a.b.c" */
23072330
int i;
@@ -2974,6 +2997,7 @@ static stmt_ty
29742997
ast_for_classdef(struct compiling *c, const node *n, asdl_seq *decorator_seq)
29752998
{
29762999
/* classdef: 'class' NAME ['(' arglist ')'] ':' suite */
3000+
PyObject *classname;
29773001
asdl_seq *s;
29783002
expr_ty call, dummy;
29793003

@@ -2983,16 +3007,22 @@ ast_for_classdef(struct compiling *c, const node *n, asdl_seq *decorator_seq)
29833007
s = ast_for_suite(c, CHILD(n, 3));
29843008
if (!s)
29853009
return NULL;
2986-
return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), NULL, NULL, NULL, NULL, s,
2987-
decorator_seq, LINENO(n), n->n_col_offset, c->c_arena);
3010+
classname = NEW_IDENTIFIER(CHILD(n, 1));
3011+
if (!classname)
3012+
return NULL;
3013+
return ClassDef(classname, NULL, NULL, NULL, NULL, s, decorator_seq,
3014+
LINENO(n), n->n_col_offset, c->c_arena);
29883015
}
29893016

29903017
if (TYPE(CHILD(n, 3)) == RPAR) { /* class NAME '(' ')' ':' suite */
29913018
s = ast_for_suite(c, CHILD(n,5));
29923019
if (!s)
2993-
return NULL;
2994-
return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), NULL, NULL, NULL, NULL, s,
2995-
decorator_seq, LINENO(n), n->n_col_offset, c->c_arena);
3020+
return NULL;
3021+
classname = NEW_IDENTIFIER(CHILD(n, 1));
3022+
if (!classname)
3023+
return NULL;
3024+
return ClassDef(classname, NULL, NULL, NULL, NULL, s, decorator_seq,
3025+
LINENO(n), n->n_col_offset, c->c_arena);
29963026
}
29973027

29983028
/* class NAME '(' arglist ')' ':' suite */
@@ -3004,9 +3034,11 @@ ast_for_classdef(struct compiling *c, const node *n, asdl_seq *decorator_seq)
30043034
s = ast_for_suite(c, CHILD(n, 6));
30053035
if (!s)
30063036
return NULL;
3037+
classname = NEW_IDENTIFIER(CHILD(n, 1));
3038+
if (!classname)
3039+
return NULL;
30073040

3008-
return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)),
3009-
call->v.Call.args, call->v.Call.keywords,
3041+
return ClassDef(classname, call->v.Call.args, call->v.Call.keywords,
30103042
call->v.Call.starargs, call->v.Call.kwargs, s,
30113043
decorator_seq, LINENO(n), n->n_col_offset, c->c_arena);
30123044
}

0 commit comments

Comments
 (0)