diff options
author | Father Chrysostomos <sprout@cpan.org> | 2016-05-19 18:27:24 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2016-05-20 15:56:38 -0700 |
commit | a061ab0bf2cb11304132a96f31a2b0403912e9b6 (patch) | |
tree | c6a541f3dd74d6505c19605a7b48e94c2afb98d0 /doop.c | |
parent | 5ad999257778c656213e977c2fd782e515f02bad (diff) | |
download | perl-a061ab0bf2cb11304132a96f31a2b0403912e9b6.tar.gz |
[perl #128187] Forbid sub :lvalue{keys} in aassign
This commit makes perl die when keys(%hash) is returned from an lvalue
sub and the lvalue sub call is assigned to in list assignment:
sub foo : lvalue { keys(%INC) }
(foo) = 3; # death
This prevents an assignment that is completely useless and probably a
mistake, and it makes the lvalue-sub use of keys behave the same way
as (keys(%INC)) = 3.
Diffstat (limited to 'doop.c')
-rw-r--r-- | doop.c | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -1273,6 +1273,13 @@ Perl_do_kv(pTHX) RETURN; } + if (UNLIKELY(PL_op->op_private & OPpMAYBE_LVSUB)) { + const I32 flags = is_lvalue_sub(); + if (flags && !(flags & OPpENTERSUB_INARGS)) + /* diag_listed_as: Can't modify %s in %s */ + Perl_croak(aTHX_ "Can't modify keys in list assignment"); + } + /* 2*HvUSEDKEYS() should never be big enough to truncate or wrap */ assert(HvUSEDKEYS(keys) <= (SSize_t_MAX >> 1)); extend_size = (SSize_t)HvUSEDKEYS(keys) * (dokeys + dovalues); |