Subject: | BER_length returns uninitialized value |
Date: | Tue, 09 Sep 2014 05:54:18 -0700 |
To: | bug-Math-Int64 [...] rt.cpan.org |
From: | Mark Donovan <mdonovan [...] mac.com> |
Math::Int64 0.30
Perl v5.16.2
Darwin Kernel Version 13.3.0 (Mac OS X 10.9)
Problem:
Int64.xs:573 warning: & has lower precedence than ==; == will be evaluated
first
(pv[i] & 0x80 == 0) is never true because 0x80 == 0 is false.
To reproduce:
my $i64 = int64(0xdeadbeef);
my $ber = int64_to_BER($i64);
print BER_length($ber);
Expected result: 5
Result: Use of uninitialized value in print
*** Int64-old.xs 2013-06-03 08:52:18.000000000 -0700
--- Int64.xs 2014-09-08 22:06:07.000000000 -0700
***************
*** 570,576 ****
unsigned char *pv = SvPVbyte(sv, len);
IV i;
for (i = 0; i < len; i++) {
! if (pv[i] & 0x80 == 0) return i + 1;
}
return -1;
}
--- 570,576 ----
unsigned char *pv = SvPVbyte(sv, len);
IV i;
for (i = 0; i < len; i++) {
! if ((pv[i] & 0x80) == 0) return i + 1;
}
return -1;
}
There are no tests for BER_length.
--