From: perl5-porters[at]ton.iguana.be (Ton Hospel)
Message-ID: <ctg2r7$j0e$4[at]post.home.lunix>
Ensure that with the C format, unpack checksums
don't get overflowed. (plus a regression test)
p4raw-id: //depot/perl@23922
uchar_checksum:
while (len-- > 0) {
auint = *s++ & 255;
- cuv += auint;
+ if (checksum > bits_in_uv)
+ cdouble += (NV)auint;
+ else
+ cuv += auint;
}
}
else {
if (checksum) {
if (strchr("fFdD", TYPE_NO_MODIFIERS(datumtype)) ||
(checksum > bits_in_uv &&
- strchr("csSiIlLnNUvVqQjJ", TYPE_NO_MODIFIERS(datumtype))) ) {
+ strchr("cCsSiIlLnNUvVqQjJ", TYPE_NO_MODIFIERS(datumtype))) ) {
NV trouble;
adouble = (NV) (1 << (checksum & 15));
my $no_signedness = $] > 5.009 ? '' :
"Signed/unsigned pack modifiers not available on this perl";
-plan tests => 13856;
+plan tests => 13857;
use strict;
use warnings;
my (@x) = unpack("b10a", "abcd");
my (@y) = unpack("%b10a", "abcd");
is($x[1], $y[1], "checksum advance ok");
+
+ # verify that the checksum is not overflowed with C0
+ is(unpack("C0%128U", "abcd"), unpack("U0%128U", "abcd"), "checksum not overflowed");
}