summaryrefslogtreecommitdiff
path: root/hv.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2021-10-16 07:52:56 +0000
committerNicholas Clark <nick@ccl4.org>2021-10-20 15:34:23 +0000
commit7c4cc0343c223680358a798ea6826c8c3a710db3 (patch)
treeae5a1b05c2476ea9c6122c66700c9acf705bcd45 /hv.c
parent638b4d9051af3a8aa432795a1f33508001c1754e (diff)
downloadperl-7c4cc0343c223680358a798ea6826c8c3a710db3.tar.gz
Perl_newHVhv() did not correctly copy hashes with non-shared keys
It created a hash built with non-shared keys, but left the "shared keys" flag set on the hash. This hasn't been spotted in 20 years, which shows just how much we use hashes with unshared keys.
Diffstat (limited to 'hv.c')
-rw-r--r--hv.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/hv.c b/hv.c
index c821f78054..06fe493f3f 100644
--- a/hv.c
+++ b/hv.c
@@ -1593,6 +1593,14 @@ Perl_newHVhv(pTHX_ HV *ohv)
Newx(a, PERL_HV_ARRAY_ALLOC_BYTES(hv_max+1), char);
ents = (HE**)a;
+ if (shared) {
+ /* Shared is the default - it should have been set by newHV(). */
+ assert(HvSHAREKEYS(hv));
+ }
+ else {
+ HvSHAREKEYS_off(hv);
+ }
+
/* In each bucket... */
for (i = 0; i <= hv_max; i++) {
HE *prev = NULL;