From: Robin Houston Date: Tue, 13 Feb 2007 16:50:08 +0000 (+0000) Subject: Re: Segmentation fault at undeclared for loop variable X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0be9a6bb1b5e18271161468546f0c905b271ab20;p=p5sagit%2Fp5-mst-13.2.git Re: Segmentation fault at undeclared for loop variable Message-Id: p4raw-id: //depot/perl@30267 --- diff --git a/op.c b/op.c index 92d0cfc..0191844 100644 --- a/op.c +++ b/op.c @@ -4521,7 +4521,15 @@ Perl_newFOROP(pTHX_ I32 flags, char *label, line_t forline, OP *sv, OP *expr, OP iterpflags = sv->op_private & OPpOUR_INTRO; /* for our $x () */ sv->op_type = OP_RV2GV; sv->op_ppaddr = PL_ppaddr[OP_RV2GV]; - if (cGVOPx_gv(cUNOPx(sv)->op_first) == PL_defgv) + + /* The op_type check is needed to prevent a possible segfault + * if the loop variable is undeclared and 'strict vars' is in + * effect. This is illegal but is nonetheless parsed, so we + * may reach this point with an OP_CONST where we're expecting + * an OP_GV. + */ + if (cUNOPx(sv)->op_first->op_type == OP_GV + && cGVOPx_gv(cUNOPx(sv)->op_first) == PL_defgv) iterpflags |= OPpITER_DEF; } else if (sv->op_type == OP_PADSV) { /* private variable */