summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Leach <richardleach@users.noreply.github.com>2021-04-02 23:51:45 +0100
committerHugo van der Sanden <hv@crypt.org>2021-04-05 14:09:50 +0100
commitce9f3c9c0043030e2d05cbb64bbfd4d50fc94b6b (patch)
tree22960f62af3abab1c10da877441a5d717fe7730e
parentd23c9e49d142b3a749181a63a9f694a97ab76185 (diff)
downloadperl-ce9f3c9c0043030e2d05cbb64bbfd4d50fc94b6b.tar.gz
av_extend_guts: set correct ary_offset when unshifting an array (GH#18667)
-rw-r--r--av.c1
-rw-r--r--t/op/splice.t6
2 files changed, 7 insertions, 0 deletions
diff --git a/av.c b/av.c
index ff0cb2340c..bf19c439c4 100644
--- a/av.c
+++ b/av.c
@@ -110,6 +110,7 @@ Perl_av_extend_guts(pTHX_ AV *av, SSize_t key, SSize_t *maxp, SV ***allocp,
if (av && *allocp != *arrayp) { /* a shifted SV* array exists */
to_null = *arrayp - *allocp;
*maxp += to_null;
+ ary_offset = AvFILLp(av) + 1;
Move(*arrayp, *allocp, AvFILLp(av)+1, SV*);
diff --git a/t/op/splice.t b/t/op/splice.t
index c786802354..abf497d9fb 100644
--- a/t/op/splice.t
+++ b/t/op/splice.t
@@ -108,4 +108,10 @@ is sprintf("%s", splice @a, 0, 1, undef), "",
"croak when splicing into readonly array";
}
+# GH#18667 - av_extend_guts must zero duplicate SV*s
+fresh_perl_is('my @data = (undef) x 4; splice @data, 1, 1;
+ splice @data, 2, 1; $data[3] = undef; splice @data, 3, 1;',
+ '', {}, 'GH#18667 - av_extend_guts must zero duplicate SV*s');
+
+
done_testing;