From 1667b8c40557fa2e47fbd78dacae709383d83aa6 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Mon, 28 Jan 2019 08:34:32 -0800 Subject: [PATCH] Add guards to some '== TYPE_COMMENT' checks, hopefully fixing a crash --- Python/ast.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Python/ast.c b/Python/ast.c index e18b20ea003e..0da33f7a9c0d 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -1538,7 +1538,7 @@ ast_for_arguments(struct compiling *c, const node *n) return NULL; asdl_seq_SET(posargs, k++, arg); i += 1; /* the name */ - if (TYPE(CHILD(n, i)) == COMMA) + if (i < NCH(n) && TYPE(CHILD(n, i)) == COMMA) i += 1; /* the comma, if present */ break; case STAR: @@ -1554,7 +1554,7 @@ ast_for_arguments(struct compiling *c, const node *n) int res = 0; i += 2; /* now follows keyword only arguments */ - if (TYPE(CHILD(n, i)) == TYPE_COMMENT) { + if (i < NCH(n) && TYPE(CHILD(n, i)) == TYPE_COMMENT) { ast_error(c, CHILD(n, i), "bare * has associated type comment"); return NULL; @@ -1571,10 +1571,10 @@ ast_for_arguments(struct compiling *c, const node *n) return NULL; i += 2; /* the star and the name */ - if (TYPE(CHILD(n, i)) == COMMA) + if (i < NCH(n) && TYPE(CHILD(n, i)) == COMMA) i += 1; /* the comma, if present */ - if (TYPE(CHILD(n, i)) == TYPE_COMMENT) { + if (i < NCH(n) && TYPE(CHILD(n, i)) == TYPE_COMMENT) { vararg->type_comment = NEW_TYPE_COMMENT(CHILD(n, i)); i += 1; } -- 2.47.3