Skip to content

Commit 5d1ff94

Browse files
committed
set Print.values to NULL if there are no values
1 parent 0805b28 commit 5d1ff94

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

Python/ast.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,9 +2144,9 @@ ast_for_print_stmt(struct compiling *c, const node *n)
21442144
| '>>' test [ (',' test)+ [','] ] )
21452145
*/
21462146
expr_ty dest = NULL, expression;
2147-
asdl_seq *seq;
2147+
asdl_seq *seq = NULL;
21482148
bool nl;
2149-
int i, j, start = 1;
2149+
int i, j, values_count, start = 1;
21502150

21512151
REQ(n, print_stmt);
21522152
if (NCH(n) >= 2 && TYPE(CHILD(n, 1)) == RIGHTSHIFT) {
@@ -2155,14 +2155,17 @@ ast_for_print_stmt(struct compiling *c, const node *n)
21552155
return NULL;
21562156
start = 4;
21572157
}
2158-
seq = asdl_seq_new((NCH(n) + 1 - start) / 2, c->c_arena);
2159-
if (!seq)
2160-
return NULL;
2161-
for (i = start, j = 0; i < NCH(n); i += 2, ++j) {
2162-
expression = ast_for_expr(c, CHILD(n, i));
2163-
if (!expression)
2158+
values_count = (NCH(n) + 1 - start) / 2;
2159+
if (values_count) {
2160+
seq = asdl_seq_new(values_count, c->c_arena);
2161+
if (!seq)
21642162
return NULL;
2165-
asdl_seq_SET(seq, j, expression);
2163+
for (i = start, j = 0; i < NCH(n); i += 2, ++j) {
2164+
expression = ast_for_expr(c, CHILD(n, i));
2165+
if (!expression)
2166+
return NULL;
2167+
asdl_seq_SET(seq, j, expression);
2168+
}
21662169
}
21672170
nl = (TYPE(CHILD(n, NCH(n) - 1)) == COMMA) ? false : true;
21682171
return Print(dest, seq, nl, LINENO(n), n->n_col_offset, c->c_arena);

0 commit comments

Comments
 (0)