]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add guards to some '== TYPE_COMMENT' checks, hopefully fixing a crash
authorGuido van Rossum <guido@python.org>
Mon, 28 Jan 2019 16:34:32 +0000 (08:34 -0800)
committerGuido van Rossum <guido@python.org>
Mon, 28 Jan 2019 16:35:52 +0000 (08:35 -0800)
Python/ast.c

index e18b20ea003e1c55a54fe328272da5c908e2b47b..0da33f7a9c0d0001205b3666b209b04c59814e15 100644 (file)
@@ -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;
                     }