Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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.
  • Loading branch information...
commit 73ff03e80797f5abfbbb570cc398cc59078bc6d5 1 parent 8fa7738
@ikegami ikegami authored Father Chrysostomos committed
Showing with 2 additions and 14 deletions.
  1. +2 −14 doop.c
View
16 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,
Please sign in to comment.
Something went wrong with that request. Please try again.