From: perl-5.8.0@ton.iguana.be Date: Sat, 5 Feb 2005 18:09:00 +0000 (+0000) Subject: [perl #34062] pack Z0 destroys the character before X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f0df5f8b34ab27424e2b758635888ff39aa69398;p=p5sagit%2Fp5-mst-13.2.git [perl #34062] pack Z0 destroys the character before From: perl-5.8.0@ton.iguana.be (via RT) Message-ID: (plus a regression test) p4raw-id: //depot/perl@23946 --- diff --git a/pp_pack.c b/pp_pack.c index 3ee7128..690cd35 100644 --- a/pp_pack.c +++ b/pp_pack.c @@ -2107,7 +2107,7 @@ S_pack_rec(pTHX_ SV *cat, register tempsym_t* symptr, register SV **beglist, SV } if ((I32)fromlen >= len) { sv_catpvn(cat, aptr, len); - if (datumtype == 'Z') + if (datumtype == 'Z' && len > 0) *(SvEND(cat)-1) = '\0'; } else { diff --git a/t/op/pack.t b/t/op/pack.t index e51cc47..3255806 100755 --- a/t/op/pack.t +++ b/t/op/pack.t @@ -12,7 +12,7 @@ my $no_endianness = $] > 5.009 ? '' : my $no_signedness = $] > 5.009 ? '' : "Signed/unsigned pack modifiers not available on this perl"; -plan tests => 13863; +plan tests => 13864; use strict; use warnings; @@ -1518,3 +1518,9 @@ is(unpack('c'), 65, "one-arg unpack (change #18751)"); # defaulting to $_ is(join(',', unpack("aU0C/UU", "b\0\341\277\274")), 'b,8188'); is(join(',', unpack("aU0C/CU", "b\0\341\277\274")), 'b,8188'); } + +{ + # "Z0" (bug #34062) + my (@x) = unpack("C*", pack("CZ0", 1, "b")); + is(join(',', @x), '1', 'pack Z0 doesn\'t destroy the character before'); +}