summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Burlison <Alan.Burlison@uk.sun.com>2003-11-19 14:39:03 +0000
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2003-11-19 19:56:20 +0000
commit5f099cb0574fe51d7450374a7827fa9383ec0061 (patch)
treec8d5553710871948d89954766b9ba98a18be12f8
parent715961523dc15717482c3eba9a533ed292b5a722 (diff)
downloadperl-5f099cb0574fe51d7450374a7827fa9383ec0061.tar.gz
clear of empty locked hash SEGVs
Message-ID: <3FBB8087.20206@sun.com> p4raw-id: //depot/perl@21748
-rw-r--r--hv.c2
-rw-r--r--lib/Hash/Util.t16
2 files changed, 16 insertions, 2 deletions
diff --git a/hv.c b/hv.c
index 53a0b3c992..29f25a3659 100644
--- a/hv.c
+++ b/hv.c
@@ -1803,7 +1803,7 @@ Perl_hv_clear(pTHX_ HV *hv)
xhv = (XPVHV*)SvANY(hv);
- if (SvREADONLY(hv)) {
+ if (SvREADONLY(hv) && xhv->xhv_array != NULL) {
/* restricted hash: convert all keys to placeholders */
I32 i;
HE* entry;
diff --git a/lib/Hash/Util.t b/lib/Hash/Util.t
index 48cbc7c007..1c77728c27 100644
--- a/lib/Hash/Util.t
+++ b/lib/Hash/Util.t
@@ -6,7 +6,7 @@ BEGIN {
chdir 't';
}
}
-use Test::More tests => 157;
+use Test::More tests => 159;
use strict;
my @Exported_Funcs;
@@ -274,5 +274,19 @@ like( $@, qr/^Attempt to access disallowed key 'I_DONT_EXIST' in a restricted ha
}
}
+# Check clear works on locked empty hashes - SEGVs on 5.8.2.
+{
+ my %hash;
+ lock_hash(%hash);
+ %hash = ();
+ ok(keys(%hash) == 0, 'clear empty lock_hash() hash');
+}
+{
+ my %hash;
+ lock_keys(%hash);
+ %hash = ();
+ ok(keys(%hash) == 0, 'clear empty lock_keys() hash');
+}
+
my $hash_seed = hash_seed();
ok($hash_seed >= 0, "hash_seed $hash_seed");