From: Gisle Aas Date: Mon, 28 Nov 2005 04:48:18 +0000 (-0800) Subject: Storable retrieve_lscalar fails for empty strings [PATCH] X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d4aa20cb0487595042985e789c92bdecea536422;p=p5sagit%2Fp5-mst-13.2.git Storable retrieve_lscalar fails for empty strings [PATCH] Message-ID: and Message-ID: p4raw-id: //depot/perl@26243 --- diff --git a/ext/Storable/Storable.xs b/ext/Storable/Storable.xs index c63087d..86ac2c6 100644 --- a/ext/Storable/Storable.xs +++ b/ext/Storable/Storable.xs @@ -4767,6 +4767,11 @@ static SV *retrieve_lscalar(pTHX_ stcxt_t *cxt, const char *cname) sv = NEWSV(10002, len); SEEN(sv, cname, 0); /* Associate this new scalar with tag "tagnum" */ + if (len == 0) { + sv_setpvn(sv, "", 0); + return sv; + } + /* * WARNING: duplicates parts of sv_setpv and breaks SV data encapsulation. * diff --git a/ext/Storable/t/malice.t b/ext/Storable/t/malice.t index 703ce47..648b15f 100644 --- a/ext/Storable/t/malice.t +++ b/ext/Storable/t/malice.t @@ -51,7 +51,7 @@ use Test::More; # present in files, but not in things store()ed to memory $fancy = ($] > 5.007 ? 2 : 0); -plan tests => 368 + length ($byteorder) * 4 + $fancy * 8 + 1; +plan tests => 372 + length ($byteorder) * 4 + $fancy * 8; use Storable qw (store retrieve freeze thaw nstore nfreeze); require 'testlib.pl'; @@ -306,3 +306,9 @@ test_things($stored, \&freeze_and_thaw, 'string', 1); # us, which will probably alert the user that something went wrong. ok(1); } + +# Unusual in that the empty string is stored with an SX_LSCALAR marker +my $hash = store_and_retrieve("pst0\5\6\3\0\0\0\1\1\0\0\0\0\0\0\0\5empty"); +ok(!$@, "no exception"); +is(ref($hash), "HASH", "got a hash"); +is($hash->{empty}, "", "got empty element");