summaryrefslogtreecommitdiff
path: root/op.c
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgs@consttype.org>2009-10-08 11:33:06 +0200
committerRafael Garcia-Suarez <rgs@consttype.org>2009-10-08 11:33:06 +0200
commita916b30221d5aac718ed67c9a5bc9c0905daddd0 (patch)
treeb5b55c48722e5eea58e49418a528ca1e8156aa11 /op.c
parent89a1beee8b93cc4ed470409e5b695b5abfd300a5 (diff)
downloadperl-a916b30221d5aac718ed67c9a5bc9c0905daddd0.tar.gz
Properly return a syntax error instead of segfaulting if each/keys/values is used without an argument
Diffstat (limited to 'op.c')
-rw-r--r--op.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/op.c b/op.c
index c3736fac0b..4d85e23eb4 100644
--- a/op.c
+++ b/op.c
@@ -8257,21 +8257,23 @@ OP *
Perl_ck_each(pTHX_ OP *o)
{
dVAR;
- OP *kid = cLISTOPo->op_first;
+ OP *kid = o->op_flags & OPf_KIDS ? cLISTOPo->op_first : NULL;
PERL_ARGS_ASSERT_CK_EACH;
- if (kid->op_type == OP_PADAV || kid->op_type == OP_RV2AV) {
- const unsigned new_type = o->op_type == OP_EACH ? OP_AEACH
- : o->op_type == OP_KEYS ? OP_AKEYS : OP_AVALUES;
- o->op_type = new_type;
- o->op_ppaddr = PL_ppaddr[new_type];
- }
- else if (!(kid->op_type == OP_PADHV || kid->op_type == OP_RV2HV
- || (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE)
- )) {
- bad_type(1, "hash or array", PL_op_desc[o->op_type], kid);
- return o;
+ if (kid) {
+ if (kid->op_type == OP_PADAV || kid->op_type == OP_RV2AV) {
+ const unsigned new_type = o->op_type == OP_EACH ? OP_AEACH
+ : o->op_type == OP_KEYS ? OP_AKEYS : OP_AVALUES;
+ o->op_type = new_type;
+ o->op_ppaddr = PL_ppaddr[new_type];
+ }
+ else if (!(kid->op_type == OP_PADHV || kid->op_type == OP_RV2HV
+ || (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE)
+ )) {
+ bad_type(1, "hash or array", PL_op_desc[o->op_type], kid);
+ return o;
+ }
}
return ck_fun(o);
}