diff options
author | Father Chrysostomos <sprout@cpan.org> | 2011-01-21 08:26:50 -0800 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2011-01-21 08:29:30 -0800 |
commit | fd1d9b5c785ad0e5340c74dd6f1be27a3735e829 (patch) | |
tree | f6509401b32a2abf51feebd28ca358bf2d28752b /pp.c | |
parent | c0f8aaaaa842ec59ffd5f565760f0c9f7cfd674f (diff) | |
download | perl-fd1d9b5c785ad0e5340c74dd6f1be27a3735e829.tar.gz |
[perl #81750] Perl 5.12: undef-as-hashref bug
The addition of the boolkeys op type in commit 867fa1e2d did not
account for the fact that rv2hv (%{}) can sometimes return undef
(%$undef with strict refs turned off).
When the boolkeys op is created (and the rv2hv becomes its kid), the
rv2hv is flagged with OPf_REF, meaning that it must return a hash, not
the contents.
Perl_softrefxv in pp.c checks for that flag. If it is set, it dies
with ‘Can't use an undefined value as a HASH reference’ for unde-
fined values.
This commit changes it to make an exception if rv2hv->op_next is a
boolkeys op. It also changes pp_boolkeys to account for undef.
Diffstat (limited to 'pp.c')
-rw-r--r-- | pp.c | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -248,7 +248,10 @@ Perl_softref2xv(pTHX_ SV *const sv, const char *const what, Perl_die(aTHX_ PL_no_usym, what); } if (!SvOK(sv)) { - if (PL_op->op_flags & OPf_REF) + if ( + PL_op->op_flags & OPf_REF && + PL_op->op_next->op_type != OP_BOOLKEYS + ) Perl_die(aTHX_ PL_no_usym, what); if (ckWARN(WARN_UNINITIALIZED)) report_uninit(sv); @@ -6319,6 +6322,8 @@ PP(pp_boolkeys) dSP; HV * const hv = (HV*)POPs; + if (SvTYPE(hv) != SVt_PVHV) { XPUSHs(&PL_sv_no); RETURN; } + if (SvRMAGICAL(hv)) { MAGIC * const mg = mg_find((SV*)hv, PERL_MAGIC_tied); if (mg) { |