]> granicus.if.org Git - python/commitdiff
SF #1377897, Bus error in ast
authorNeal Norwitz <nnorwitz@gmail.com>
Sun, 11 Dec 2005 20:12:40 +0000 (20:12 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Sun, 11 Dec 2005 20:12:40 +0000 (20:12 +0000)
If a line had multiple semi-colons and ended with a semi-colon, we would
loop too many times and access a NULL node.  Exit the loop early if
there are no more children.

Lib/test/test_grammar.py
Python/ast.c

index 820fab58cbceab6894392cca3e5b3b952f9df112..aa76b44b8e481aeb76240bf95fa91c0c95e98c84 100644 (file)
@@ -276,6 +276,10 @@ check_syntax("lambda x: x = 2")
 ### simple_stmt: small_stmt (';' small_stmt)* [';']
 print 'simple_stmt'
 x = 1; pass; del x
+def foo():
+    # verify statments that end with semi-colons
+    x = 1; pass; del x;
+foo()
 
 ### small_stmt: expr_stmt | print_stmt  | pass_stmt | del_stmt | flow_stmt | import_stmt | global_stmt | access_stmt | exec_stmt
 # Tested below
index 89ec2178f2468ff4aeabd5e2730254ba721456f7..04b2b3e5f66b035998e7846e4756f7eb17c7fe0d 100644 (file)
@@ -2562,6 +2562,11 @@ ast_for_suite(struct compiling *c, const node *n)
                ch = CHILD(ch, 0);
                REQ(ch, simple_stmt);
                for (j = 0; j < NCH(ch); j += 2) {
+                   /* statement terminates with a semi-colon ';' */
+                   if (NCH(CHILD(ch, j)) == 0) {
+                       assert((j + 1) == NCH(ch));
+                       break;
+                   }
                    s = ast_for_stmt(c, CHILD(ch, j));
                    if (!s)
                        goto error;