From: Alan Burlison Date: Wed, 19 Nov 2003 14:39:03 +0000 (+0000) Subject: clear of empty locked hash SEGVs X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5f099cb0574fe51d7450374a7827fa9383ec0061;p=p5sagit%2Fp5-mst-13.2.git clear of empty locked hash SEGVs Message-ID: <3FBB8087.20206@sun.com> p4raw-id: //depot/perl@21748 --- diff --git a/hv.c b/hv.c index 53a0b3c..29f25a3 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 48cbc7c..1c77728 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");