Re: encoding neutral unpack
authorTon Hospel <perl5-porters@ton.iguana.be>
Sat, 29 Jan 2005 12:41:20 +0000 (12:41 +0000)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Mon, 31 Jan 2005 23:08:59 +0000 (23:08 +0000)
From: perl5-porters[at]ton.iguana.be (Ton Hospel)
Message-ID: <ctg09g$j0e$1[at]post.home.lunix>

Forgotten character progress while checksumming over partial
b or B format. (plus a regression test)

p4raw-id: //depot/perl@23915

pp_pack.c
t/op/pack.t

index 8f76d69..cb3dd89 100644 (file)
--- a/pp_pack.c
+++ b/pp_pack.c
@@ -1085,7 +1085,7 @@ S_unpack_rec(pTHX_ register tempsym_t* symptr, register char *s, char *strbeg, c
                    len -= 8;
                }
                if (len) {
-                   bits = *s;
+                   bits = *s++;
                    if (datumtype == 'b') {
                        while (len-- > 0) {
                            if (bits & 1) cuv++;
index 102a0ce..d30ae94 100755 (executable)
@@ -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 => 13855;
+plan tests => 13856;
 
 use strict;
 use warnings;
@@ -1491,3 +1491,11 @@ is(unpack('c'), 65, "one-arg unpack (change #18751)"); # defaulting to $_
     is($a[-1], "01234567\n", "[perl #15288]");
     is($a[-2], "X",          "[perl #15288]");
 }
+
+# checksums
+{
+    # verify that unpack advances correctly wrt a checksum
+    my (@x) = unpack("b10a", "abcd");
+    my (@y) = unpack("%b10a", "abcd");
+    is($x[1], $y[1], "checksum advance ok");
+}