From: Guido van Rossum Date: Mon, 28 Jan 2019 16:34:32 +0000 (-0800) Subject: Add guards to some '== TYPE_COMMENT' checks, hopefully fixing a crash X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1667b8c40557fa2e47fbd78dacae709383d83aa6;p=thirdparty%2FPython%2Fcpython.git Add guards to some '== TYPE_COMMENT' checks, hopefully fixing a crash --- 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; }