From 73ff03e80797f5abfbbb570cc398cc59078bc6d5 Mon Sep 17 00:00:00 2001 From: Eric Brine Date: Wed, 24 Aug 2011 20:10:43 -0700 Subject: [PATCH] Trim dead code in do_kv. A small piece of code in do_kv has three bugs: - TARG could have been returned as an lvalue, so its refcount could be greater than 1, resulting in data getting clobbered. (See RT#20933 for previously fixed occurrence of this bug). - LvTARG is refcounted, so it's buggy to just NULL it. - TARG is returned without being initialised. The first two bugs disappeared recently when we stopped putting the lvalues in TARG for that op. The third remains. However, it seems that code is never called. It can only be called by putting NULL (not undef) on the Perl stack. I don't see how that's possible here. The test suite never reaches that code, so it seems it's just dead code. --- doop.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/doop.c b/doop.c index c11555f..e31fae2 100644 --- a/doop.c +++ b/doop.c @@ -1224,8 +1224,7 @@ Perl_do_kv(pTHX) { dVAR; dSP; - HV * const hv = MUTABLE_HV(POPs); - HV *keys; + HV * const keys = MUTABLE_HV(POPs); register HE *entry; const I32 gimme = GIMME_V; const I32 dokv = (PL_op->op_type == OP_RV2HV || PL_op->op_type == OP_PADHV); @@ -1233,17 +1232,6 @@ Perl_do_kv(pTHX) const I32 dokeys = dokv || (PL_op->op_type == OP_KEYS || PL_op->op_type == OP_RKEYS); const I32 dovalues = dokv || (PL_op->op_type == OP_VALUES || PL_op->op_type == OP_RVALUES); - if (!hv) { - if (PL_op->op_flags & OPf_MOD || LVRET) { /* lvalue */ - dTARGET; /* make sure to clear its target here */ - if (SvTYPE(TARG) == SVt_PVLV) - LvTARG(TARG) = NULL; - PUSHs(TARG); - } - RETURN; - } - - keys = hv; (void)hv_iterinit(keys); /* always reset iterator regardless */ if (gimme == G_VOID) @@ -1285,7 +1273,7 @@ Perl_do_kv(pTHX) if (dovalues) { SV *tmpstr; PUTBACK; - tmpstr = hv_iterval(hv,entry); + tmpstr = hv_iterval(keys,entry); DEBUG_H(Perl_sv_setpvf(aTHX_ tmpstr, "%lu%%%d=%lu", (unsigned long)HeHASH(entry), (int)HvMAX(keys)+1, -- 2.7.4