diff --git a/av.c b/av.c index 352c1ac03491..3a83fec6ff94 100644 --- a/av.c +++ b/av.c @@ -361,7 +361,7 @@ Perl_av_store(pTHX_ AV *av, SSize_t key, SV *val) return NULL; } - if (SvREADONLY(av) && key >= AvFILL(av)) + if (SvREADONLY(av) && key > AvFILL(av)) croak_no_modify(); if (!AvREAL(av) && AvREIFY(av)) diff --git a/t/op/array.t b/t/op/array.t index cde0ad1251e6..79186b0c6464 100644 --- a/t/op/array.t +++ b/t/op/array.t @@ -6,7 +6,7 @@ BEGIN { set_up_inc('.', '../lib'); } -plan (198); +plan (199); # # @foo, @bar, and @ary are also used from tie-stdarray after tie-ing them @@ -734,3 +734,15 @@ fresh_perl_is('my @x;$x[0] = 1;shift @x;$x[22] = 1;$x[25] = 1;','', is($arr[1], 3, 'Array element within array range created at correct index from subroutine @_ alias; GH 16364'); } + +# regression test for GH #24006 +{ + use feature qw(refaliasing); + no warnings 'experimental::refaliasing'; + my @arr = (1, 2); + Internals::SvREADONLY(@arr, 1); + + eval { \$arr[1] = \42 }; + ok !$@, "Last element's contents of a readonly array can be modified"; +} +