fix float to int conversions on ARM CPU's

This commit is contained in:
terrafrost 2017-12-09 18:16:48 -06:00
parent ab5158dcd3
commit b25681beeb
2 changed files with 15 additions and 9 deletions

View File

@ -550,7 +550,7 @@ class Crypt_Blowfish extends Crypt_Base
// on 32-bit linux systems with PHP < 5.3 float to integer conversion is bad // on 32-bit linux systems with PHP < 5.3 float to integer conversion is bad
switch (true) { switch (true) {
case defined('PHP_INT_SIZE') && PHP_INT_SIZE == 8: case defined('PHP_INT_SIZE') && PHP_INT_SIZE == 8:
case version_compare(PHP_VERSION, '5.3.0') >= 0: case version_compare(PHP_VERSION, '5.3.0') >= 0 && (php_uname('m') & "\xDF\xDF\xDF") != 'ARM':
case (PHP_OS & "\xDF\xDF\xDF") === 'WIN': case (PHP_OS & "\xDF\xDF\xDF") === 'WIN':
$safeint = '%s'; $safeint = '%s';
break; break;
@ -663,10 +663,13 @@ class Crypt_Blowfish extends Crypt_Base
*/ */
function safe_intval($x) function safe_intval($x)
{ {
// PHP 5.3, per http://php.net/releases/5_3_0.php, introduced "more consistent float rounding" switch (true) {
// PHP_OS & "\xDF\xDF\xDF" == strtoupper(substr(PHP_OS, 0, 3)), but a lot faster case is_int($x):
if (is_int($x) || version_compare(PHP_VERSION, '5.3.0') >= 0 || (PHP_OS & "\xDF\xDF\xDF") === 'WIN') { // PHP 5.3, per http://php.net/releases/5_3_0.php, introduced "more consistent float rounding"
return $x; case version_compare(PHP_VERSION, '5.3.0') >= 0 && (php_uname('m') & "\xDF\xDF\xDF") != 'ARM':
// PHP_OS & "\xDF\xDF\xDF" == strtoupper(substr(PHP_OS, 0, 3)), but a lot faster
case (PHP_OS & "\xDF\xDF\xDF") === 'WIN':
return $x;
} }
return (fmod($x, 0x80000000) & 0x7FFFFFFF) | return (fmod($x, 0x80000000) & 0x7FFFFFFF) |
((fmod(floor($x / 0x80000000), 2) & 1) << 31); ((fmod(floor($x / 0x80000000), 2) & 1) << 31);

View File

@ -832,10 +832,13 @@ class Crypt_Hash
$result+= $argument < 0 ? ($argument & 0x7FFFFFFF) + 0x80000000 : $argument; $result+= $argument < 0 ? ($argument & 0x7FFFFFFF) + 0x80000000 : $argument;
} }
// PHP 5.3, per http://php.net/releases/5_3_0.php, introduced "more consistent float rounding" switch (true) {
// PHP_OS & "\xDF\xDF\xDF" == strtoupper(substr(PHP_OS, 0, 3)), but a lot faster case is_int($result):
if (is_int($result) || version_compare(PHP_VERSION, '5.3.0') >= 0 || (PHP_OS & "\xDF\xDF\xDF") === 'WIN') { // PHP 5.3, per http://php.net/releases/5_3_0.php, introduced "more consistent float rounding"
return fmod($result, $mod); case version_compare(PHP_VERSION, '5.3.0') >= 0 && (php_uname('m') & "\xDF\xDF\xDF") != 'ARM':
// PHP_OS & "\xDF\xDF\xDF" == strtoupper(substr(PHP_OS, 0, 3)), but a lot faster
case (PHP_OS & "\xDF\xDF\xDF") === 'WIN':
return fmod($result, $mod);
} }
return (fmod($result, 0x80000000) & 0x7FFFFFFF) | return (fmod($result, 0x80000000) & 0x7FFFFFFF) |