Bug #51397 [Opn->Ver]: Math calculation bug

[email protected] Fri, 26 Mar 2010 11:56:42 +0100 (CET)
Newsgroups php.bugs
Message-ID <[email protected]>
Edit report at http://bugs.php.net/bug.php?id=51397&edit=1

 ID:               51397
 Updated by:       [email protected]
 Reported by:      emanuel dot dejanu at humaninfo dot ro
 Summary:          Math calculation bug
-Status:           Open
+Status:           Verified
 Type:             Bug
 Package:          Scripting Engine problem
 Operating System: FREEBSD & LINUX
 PHP Version:      5.2.13

 New Comment:

Verified with 5.2.13 on Debian (default configure)

Verified in the Debian 5.2.6+lenny4 PHP (just for completeness)

Correct result with 5.3.2 on Gentoo


Previous Comments:
------------------------------------------------------------------------
[2010-03-26 08:20:19] emanuel dot dejanu at humaninfo dot ro

Description:
------------

I have used the code from the test script on my development machine
(Windows Professional 7 32bit) with php 5.2.12 and is working correctly
but when I have deployed on my production machine that is FreeBSD 6.3
32bit with the same php version 5.2.12 is giving wrong results
(-2147483593). I also run this on other production machine that is
RedHat 5 32bit with php 5.2.6 and is also giving wrong results
(-2147483593).

I can not test with php 5.2.13 on production machines (virtual
hosting).
On windows is giving the correctly result (754303898) with PHP 5.2.12
and PHP 5.3.1. I am running in 32bit platform on all machines.

-------------------------------------------------------------------

PHP_INT_SIZE: 4

System => FreeBSD somehost.com 6.3-RELEASE FreeBSD 6.3-RELEASE #6: Wed
Oc
t 21 09:32:42 MDT 2009     root@fc:/usr/src/sys/i386/compile/VKERN i386
Build Date => Mar  3 2010 12:51:00
Configure Command =>  './configure'  '--with-layout=GNU'
'--with-config-file-sca
n-dir=/usr/local/etc/php' '--disable-all' '--enable-libxml'
'--with-libxml-dir=/
usr/local' '--enable-reflection' '--program-prefix=' '--enable-fastcgi'
'--with-
apxs2=/usr/local/sbin/apxs' '--with-regex=php' '--with-zend-vm=CALL'
'--prefix=/
usr/local' '--mandir=/usr/local/man' '--infodir=/usr/local/info/'
'--build=i386-
portbld-freebsd6.3'
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /usr/local/etc
Loaded Configuration File => /usr/local/etc/php.ini
Scan this dir for additional .ini files => /usr/local/etc/php
additional .ini files parsed => /usr/local/etc/php/extensions.ini

PHP API => 20041225
PHP Extension => 20060613
Zend Extension => 220060519
Debug Build => no



Test script:
---------------
function myhash($key) {
        $h = 5381;
        $l = strlen($key);
        for($i = 0; $i < $l; ++$i) {
            $h = (($h << 5) + $h) ^ ord($key[$i]);
        }
        return $h;
}
$h = myhash('CL6.1.7');
if ($h != 754303898)
        echo "bug\n";
echo $h . "\n";


Expected result:
----------------
754303898


Actual result:
--------------
bug
-2147483593


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=51397&edit=1