bug #3678 Does not display or manipulate bit(64) fields appropriately

This commit is contained in:
Marc Delisle 2013-10-09 10:06:47 -04:00
parent 09593ec25b
commit 4fb5088f86
3 changed files with 29 additions and 6 deletions

View File

@ -6,6 +6,7 @@ phpMyAdmin - ChangeLog
- bug #4108 Missing refresh by deleting databases
- bug #3995 Drizzle server charset notice
- bug #3911 Filtering database names includes empty groupings
- bug #3678 Does not display or manipulate bit(64) fields appropriately
4.0.8.0 (2013-10-06)
- bug #3988 Rename view is not working

View File

@ -3000,6 +3000,7 @@ class PMA_Util
* Converts a bit value to printable format;
* in MySQL a BIT field can be from 1 to 64 bits so we need this
* function because in PHP, decbin() supports only 32 bits
* on 32-bit servers
*
* @param numeric $value coming from a BIT field
* @param integer $length length
@ -3008,11 +3009,32 @@ class PMA_Util
*/
public static function printableBitValue($value, $length)
{
$printable = '';
for ($i = 0, $len_ceiled = ceil($length / 8); $i < $len_ceiled; $i++) {
$printable .= sprintf('%08d', decbin(ord(substr($value, $i, 1))));
// if running on a 64-bit server or the length is safe for decbin()
if (PHP_INT_SIZE == 8 || $length < 33) {
$printable = decbin($value);
} else {
// FIXME: does not work for the leftmost bit of a 64-bit value
$i = 0;
$printable = '';
while ($value >= pow(2, $i)) {
$i++;
}
if ($i != 0) {
$i = $i - 1;
}
while ($i >= 0) {
if ($value - pow(2, $i) < 0) {
$printable = '0' . $printable;
} else {
$printable = '1' . $printable;
$value = $value - pow(2, $i);
}
$i--;
}
$printable = strrev($printable);
}
$printable = substr($printable, -$length);
$printable = str_pad($printable, $length, '0', STR_PAD_LEFT);
return $printable;
}

View File

@ -23,8 +23,8 @@ class PMA_PrintableBitValueTest extends PHPUnit_Framework_TestCase
public function printableBitValueDataProvider()
{
return array(
array('testtest', 64, '0111010001100101011100110111010001110100011001010111001101110100'),
array('test', 32, '01110100011001010111001101110100')
array('20131009', 64, '0000000000000000000000000000000000000001001100110010110011000001'),
array('5', 32, '00000000000000000000000000000101')
);
}