summaryrefslogtreecommitdiffstats
path: root/Python/ast.c
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2008-07-17 16:37:17 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2008-07-17 16:37:17 (GMT)
commite921e02a2e97cc418a1c8faec135056802849864 (patch)
tree9cdcd0dea2a9ca50162eb03ee8a976cf19ed6b88 /Python/ast.c
parentc3fee694644cdf24bfb974dcd924fbdf524350ee (diff)
downloadcpython-e921e02a2e97cc418a1c8faec135056802849864.zip
cpython-e921e02a2e97cc418a1c8faec135056802849864.tar.gz
cpython-e921e02a2e97cc418a1c8faec135056802849864.tar.bz2
Fix uninitialized memory read for cases like def(f, *): pass
There's not much interesting here. The old code read uninitialized memory but at worst incremented i past NCH(n), but no bad effects followed from that.
Diffstat (limited to 'Python/ast.c')
-rw-r--r--Python/ast.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/Python/ast.c b/Python/ast.c
index 6ec2ef1..9adb5a2 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -742,15 +742,21 @@ ast_for_arguments(struct compiling *c, const node *n)
}
assert(TYPE(n) == typedargslist || TYPE(n) == varargslist);
- /* first count the number of positional args & defaults */
+ /* First count the number of positional args & defaults. The
+ variable i is the loop index for this for loop and the next.
+ The next loop picks up where the first leaves off.
+ */
for (i = 0; i < NCH(n); i++) {
ch = CHILD(n, i);
if (TYPE(ch) == STAR) {
- /* skip star and possible argument */
+ /* skip star */
i++;
- i += (TYPE(CHILD(n, i)) == tfpdef
- || TYPE(CHILD(n, i)) == vfpdef);
- break;
+ if (i < NCH(n) && /* skip argument following star */
+ (TYPE(CHILD(n, i)) == tfpdef ||
+ TYPE(CHILD(n, i)) == vfpdef)) {
+ i++;
+ }
+ break;
}
if (TYPE(ch) == DOUBLESTAR) break;
if (TYPE(ch) == vfpdef || TYPE(ch) == tfpdef) nposargs++;